Replace Lines Matching A Pattern

I have several files in that I need to add the text "N CHAR(1)," How can I accomplish this in linux without having to do it manually. Thanks

HAVE

nullcols
(A "to_number(:A,'9')"
,B CHAR(50)
)

WANT

nullcols
(N CHAR(1)
,A "to_number(:A,'9')"
,B CHAR(50)
)


Similar Content



Problems With "error: Invalid Conversion From `const Char*' To `char*' "

Hi, I need some help. I tried to install obs-ns. Itīs based on ns2, but when I ran "make", the problem below appears... please I wish anybody would help me.


This is the error:

Code:
OBS/ns-2/integrated_agent.h: In constructor `BurstManager::BurstManager()':
OBS/ns-2/integrated_agent.h:86: warning: `BurstManager::bt_' will be initialized after
OBS/ns-2/integrated_agent.h:84: warning:   `int BurstManager::currburstsize_'
OBS/ns-2/integrated_agent.cc:66: warning:   when initialized here
OBS/ns-2/integrated_agent.cc: In member function `int BurstManager::nhops(nsaddr_t, nsaddr_t)':
OBS/ns-2/integrated_agent.cc:81: error: invalid conversion from `const char*' to `char*'   <------- this is the error 
OBS/ns-2/integrated_agent.cc: In member function `virtual void IPKTAgent::recv(Packet*, Handler*)':
OBS/ns-2/integrated_agent.cc:180: warning: unused variable 'ipkth'
/root/OBS/ns-allinone-2.31/tclcl-1.19/tclcl.h:150: error: `void Tcl::error(const char*)' is private
OBS/ns-2/integrated_agent.cc:185: error: within this context
OBS/ns-2/integrated_agent.cc:155: warning: unused variable 'hdr'
OBS/ns-2/integrated_agent.cc: In member function `void IPKTAgent::deBurst(Packet*)':
OBS/ns-2/integrated_agent.cc:192: warning: unused variable 'hdrip'
OBS/ns-2/integrated_agent.cc:194: warning: unused variable 'ch'
make: *** [OBS/ns-2/integrated_agent.o] Error 1


And this is the code of the program...


Code:
int BurstManager::nhops(nsaddr_t src,nsaddr_t des) {
  Tcl& tcl = Tcl::instance();
  sprintf(tcl.buffer(),"$ns nhops %d %d",src,des);
  tcl.eval();
  char *ni = tcl.result();   <------this is the line 81 
  return atoi(ni);
}

What Are The Differences Between Character Devices And Block Devices?

Hi,

I am trying to understand the difference between char devices and block devices.
I understand the basic, which is that char devices input/output data one character at a time, whereas block device input/output data block by block. But for char device driver, most of the time we are able to read/write an array of data using the read/write system call. This "array of data" sounds like a block of data to me, except that it's not fixed in size as for block devices. With this thinking, can I say that I can effectively achieve block read/write with a char device driver?
And what are the other differences?

Thank you all,
Wei

Cannot Say Hello To The World Due To 'code 1'

/************************************************************
*
* Project 0: My First Program in C++
*
* Author: xxx xxxx
* Date: 18 January 2015
*
* This is the canonical first program for C++.
* Its purpose is to show that one knows how to create a program in
* one's particular programming environment.
*
************************************************************/

#include <bjarne/std_lib_facilities.h>

int main()
{
cout << "Hello, world!\n";

return 0;
}

I compiled the hello world program as my prof instructed.
then I used C+c C+c, delete 'make -k' and replaced with 'g++ -o proj0 -std=c++11 proj0.cc', choose to save the file, and it goes 'compilation exited abnormally with code 1'

note that I do all these by making SSH connection with computer in lab with a linux system

FYI, the whole thing is:

-*- mode: compilation; default-directory: "~/private/cs1/proj0/" -*-
Compilation started at Sun Jan 18 21:15:54

g++ -o proj0 -std=c++11 proj0.cc
In file included from /usr/include/c++/4.9.2/locale:41:0,
from /usr/include/c++/4.9.2/iomanip:43,
from /usr/local/include/bjarne/std_lib_facilities.h:220,
from proj0.cc:14:
/usr/include/c++/4.9.2/bits/locale_facets_nonio.h:1869:5: error: template-id do_get<> for String std::messages<char>::do_get(std::messages_base::catalog, int, int, const String&) const does not match any template declaration
messages<char>::do_get(catalog, int, int, const string&) const;
^
/usr/include/c++/4.9.2/bits/locale_facets_nonio.h:1869:62: note: saw 1 template<> , need 2 for specializing a member function template
messages<char>::do_get(catalog, int, int, const string&) const;
^

Compilation exited abnormally with code 1 at Sun Jan 18 21:15:55

Help To Disperse The Data Using Bitsplitter

I am totally new to Linux. I am working on Nubisave project in TU Dresden. I am stuck in running the C program. Its bitsplitter program. Can anybody help me out? should I post the program here? Will it be helpful for me? I knnow little basics of C language and the code is totally new for me.
I have used the code of bitsplitter and it is running but I am not understanding the output. This is code from Tu Dresden. Can anybody explain me how it is working?

#include "bitsplit.h"

#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/errno.h>
#include <stdlib.h>
#include <string.h>

#define SPLITDEBUG 0

struct fillbyte_t {
char *bits;
int bitctr;
char bytes[1024];
int bytectr;
unsigned char numbits;
unsigned char shiftbits;
unsigned int pattern;
FILE *f;
char *buffer;
ssize_t bufferctr;
};
typedef struct fillbyte_t fillbyte;

struct bitsplit_t {
fillbyte *b;
int parts;
int redundant;
int totalbits;
};
typedef struct bitsplit_t bitsplit;

static void bitsplitfinish(bitsplit bs)
{
int j;

for(j = 0; j < (bs.parts + bs.redundant); j++)
{
if(bs.b[j].f)
fclose(bs.b[j].f);
free(bs.b[j].bits);
/*free(bs.b[j].buffer);*/ /* the caller clears this */
}
free(bs.b);
bs.b = NULL;
}

static bitsplit bitsplitprepare(const char *directory, int parts, int redundant, int bitwidth)
{
fillbyte *b;
bitsplit bs;
int ret;
char fname[1024];
int sumbits, totalbits;
int i, j;

bs.b = NULL;

if(directory)
{
ret = mkdir(directory, S_IRWXU);
if((ret != 0) && (errno != EEXIST)) return bs;
}

b = malloc((parts + redundant) * sizeof(fillbyte));
for(j = 0; j < (parts + redundant); j++)
{
b[j].bitctr = 0;
b[j].bytectr = 0;
b[j].buffer = NULL;
b[j].bufferctr = 0;
if(directory)
{
snprintf(fname, sizeof(fname), "%s/%i.stream", directory, j);
b[j].f = fopen(fname, "w");
}
else b[j].f = NULL;
}

sumbits = 0;
totalbits = (int)(((parts - 1) / bitwidth) + 1) * bitwidth;
#if SPLITDEBUG
printf("bitwidth: %i; totalbits: %i\n", bitwidth, totalbits);
#endif

if(redundant)
if(totalbits % parts != 0)
{
bitsplitfinish(bs);
return bs;
}

for(j = parts - 1; j >= 0; j--)
{
b[j].bits = (char*)malloc(totalbits * 8 * sizeof(char));

b[j].numbits = (int)((totalbits - sumbits) / (j + 1));
b[j].pattern = 0;
for(i = sumbits; i < sumbits + b[j].numbits; i++)
b[j].pattern |= (1 << i);
b[j].shiftbits = sumbits;
sumbits += b[j].numbits;
#if SPLITDEBUG
printf("bits: fragment %i=%i, pattern=%u\n", j, b[j].numbits, b[j].pattern);
#endif
}
for(j = parts; j < parts + redundant; j++)
{
b[j].bits = (char*)malloc(totalbits * 8 * sizeof(char));
}

bs.b = b;
bs.parts = parts;
bs.redundant = redundant;
bs.totalbits = totalbits;

return bs;
}

static int bitjoinwork(const char **inbuffers, ssize_t *insizes, bitsplit bs)
{
ssize_t i;
int j, k;
int target, revtarget;
int topk, topkcandidate;
int outbits;
int shifted;
int smallest;
int rels[16];
int inshift;

outbits = 8;
shifted = 0;

int xspecial = 0;

xspecial = 1;
if(bs.totalbits > 2 * bs.parts)
xspecial = 0;
if(xspecial)
for(j = 0; j < bs.parts; j++)
if(bs.b[j].numbits > 8) xspecial = 0;
if((bs.parts == 2) && (bs.totalbits == 11))
xspecial = 1;

if((!xspecial) && (bs.totalbits > 8))
outbits = 16;

topk = 0;
for(j = 0; j < bs.parts; j++)
{
topkcandidate = (int)((float)outbits / bs.b[j].numbits) - 1;
if(topkcandidate > topk)
topk = topkcandidate;
}
for(j = 0; j < bs.parts; j++)
{
rels[j] = (int)((topk + 1) / (outbits / bs.b[j].numbits));
// FIXME: mostly untested: =2, *=2 etc. yields 89 OKs
if((!xspecial) && (bs.totalbits > 8))
rels[j] = 2;
if(bs.b[j].numbits == 4)
{
if((bs.parts == 2) && (bs.totalbits == 9))
{
rels[j] = 1;
topk = 1;
}
}
#if SPLITDEBUG
printf("REL/%i=%i <<%i>>\n", j, rels[j], outbits);
#endif
}

smallest = (int)(insizes[0] / rels[0]);
if(((int)(float)insizes[0] * 2 / rels[0]) != smallest * 2)
smallest++;

inshift = (outbits - (topk + 1) * bs.b[0].numbits) % outbits;

int special = 0;
if((bs.parts == 2) && (bs.totalbits > 8))
special = 1;
int special2 = 0;
if((bs.parts == 2) && (bs.totalbits == 5))
special2 = 1;
if((bs.parts == 2) && (bs.totalbits == 7))
special2 = 1;
if((bs.parts == 3) && (bs.totalbits == 7))
special2 = 1;
int special3 = 0;
if((bs.parts == 5) && (bs.totalbits == 15))
special3 = 1;
if((bs.parts == 4) && (bs.totalbits == 12))
special3 = 1;
if((bs.parts == 3) && (bs.totalbits == 9))
special3 = 1;
int special4 = 0;
if((bs.parts == 3) && (bs.totalbits == 15))
special4 = 1;

target = 0;
for(i = 0; i < smallest; i++)
{
#if SPLITDEBUG
printf("- reverse source-pos:%li\n", i);
#endif
// FIXME: special; not for w=14||12, only for w=10!
if((special) && (bs.totalbits == 10) && (shifted >= 10))
{
shifted -= bs.totalbits;
if(shifted < 0)
shifted = 0;
}
#if SPLITDEBUG
printf(" remaining target:%i\n", target);
#endif

for(k = topk; k >= 0; k--)
{
for(j = bs.parts - 1; j >= 0; j--)
{
int packval = (int)(unsigned char)inbuffers[j][i * rels[j]];
// FIXME: read-ahead depends on the relative difference between numbits?
if(rels[j] == 2)
packval = (packval << 8) + (int)(unsigned char)inbuffers[j][i * rels[j] + 1];
// FIXME: special
if((!special) && (!special2) && (!special3) && (!special4))
packval >>= inshift;

int packshift = k * bs.b[j].numbits;
// FIXME: special; only for w=14||12, not for w=10!
if(special)
{
if(bs.b[j].numbits != 4)
packshift = k * 8 - bs.b[j].numbits;
if(bs.totalbits != 10)
packshift += 8;

// for 5+4 bits
if((packshift == 20) && (bs.b[j].numbits == 4))
packshift = 12;
else if((packshift == 16) && (bs.b[j].numbits == 4))
packshift = 8;
else if((packshift == 12) && (bs.b[j].numbits == 4))
packshift = 4;
else if((packshift == 8) && (bs.b[j].numbits == 4))
packshift = 0;
}
if(special2)
{
if((packshift == 9) && (bs.b[j].numbits == 3))
packshift = 13;
else if((packshift == 6) && (bs.b[j].numbits == 3))
packshift = 10;
else if((packshift == 3) && (bs.b[j].numbits == 3))
packshift = 5;
else if((packshift == 0) && (bs.b[j].numbits == 3))
packshift = 2;
}
if(special3)
{
if(packshift == 12)
packshift = 13;
else if(packshift == 9)
packshift = 10;
else if(packshift == 6)
packshift = 5;
else if(packshift == 3)
packshift = 2;
else if(packshift == 0)
continue;
}
if(special4)
{
if(packshift == 10)
packshift = 11;
else if(packshift == 5)
packshift = 3;
else if(packshift == 0)
continue;
}
#if SPLITDEBUG
printf("PACKSHIFT:%i (on val %i) [filtered:%i] [shifted:%i]\n", packshift, packval, (bs.b[j].pattern >> bs.b[j].shiftbits), shifted);
#endif
revtarget = (packval >> packshift) & (bs.b[j].pattern >> bs.b[j].shiftbits);
#if SPLITDEBUG
printf(" -> reverse target @%i[pos:%i]:%u\n", j, k, revtarget);
#endif
target += revtarget << shifted;
shifted += bs.b[j].numbits;
#if SPLITDEBUG
printf(" => target: %i (shifted:%i)\n", target, shifted);
#endif
if(shifted >= outbits)
{
while(shifted >= 8)
{
// FIXME: special; only for w>=10?
if((special) && (shifted == bs.totalbits))
break;
#if SPLITDEBUG
printf("@%li: %i [extra]\n", bs.b[0].bufferctr, target & 0xFF);
#endif
if(bs.b[0].bufferctr % 1024 == 0)
bs.b[0].buffer = (char*)realloc(bs.b[0].buffer, (bs.b[0].bufferctr + 1024) * sizeof(char));
bs.b[0].buffer[bs.b[0].bufferctr] = target & 0xFF;
shifted -= 8;
bs.b[0].bufferctr++;
target = (target - (target & 0xFF)) >> 8;
}
}
}
}
}

return 0;
}

static int bitsplitwork(const char *inbuffer, ssize_t insize, bitsplit bs)
{
ssize_t i;
int j, k, l;
int target, shifted, inshifted;
int precounted;

fillbyte *b;
int totalbits;
int parts;
int redundant;

int outbits;
int stuffingthreshold;

b = bs.b;
totalbits = bs.totalbits;
parts = bs.parts;
redundant = bs.redundant;

outbits = 8;
inshifted = 0;
stuffingthreshold = totalbits * 8;

for(i = 0; i < insize; i++)
{
if(inshifted > 8)
{
inshifted -= 8;
i += 1;
}
#if SPLITDEBUG
printf("- source-pos:%li\n", i);
#endif
for(j = 0; j < parts; j++)
{
//target = inbuffer[i] & b[j].pattern;
target = (*(int*)(inbuffer + i)) & (b[j].pattern << inshifted);
target = target >> (b[j].shiftbits + inshifted);
#if SPLITDEBUG
printf(" -> target @%i[pos:%i]:%u\n", j, b[j].bitctr, target);
#endif

b[j].bits[b[j].bitctr] = target;
b[j].bitctr++;
if(b[j].bitctr == stuffingthreshold)
{
target = 0;
shifted = outbits - b[j].numbits;
precounted = 0;
for(k = 0; k < b[j].bitctr; k++)
{
#if SPLITDEBUG
printf("@%i: (%i->%i) >> %i ; << %i\n", j, b[j].numbits, b[j].bits[k], b[j].shiftbits, shifted);
#endif
target |= (b[j].bits[k] << shifted);
shifted -= b[j].numbits;
if(shifted < 0)
{
b[j].bytes[b[j].bytectr] = target & 0xFF;
b[j].bytectr++;
shifted = outbits - b[j].numbits;
precounted++;
#if SPLITDEBUG
printf("@%i: [bytectr++]: %i {%i}\n", j, target & 0xFF, target);
#endif
target = target >> outbits;
}
}
//b[j].bytectr += (int)((b[j].numbits * totalbits * 8 - 1) / 8) + 1 - precounted;
b[j].bytectr += (int)((totalbits - 1) / 8);
#if SPLITDEBUG
printf("@%i: stuffed %i 'bits'/fragments; bytectr now %i\n", j, totalbits, b[j].bytectr);
#endif
b[j].bitctr = 0;
if(b[j].bytectr >= 1024 - stuffingthreshold)
{
if((j == 0) && (redundant))
{
#if SPLITDEBUG
printf(">> redundancy\n");
#endif
b[parts].bytectr = b[j].bytectr;
for(l = 0; l < b[parts].bytectr; l++)
{
b[parts].bytes[l] = 0;
for(k = 0; k < parts; k++)
b[parts].bytes[l] ^= b[k].bytes[l];
}
if(b[parts].f)
fwrite(b[parts].bytes, 1, b[parts].bytectr, b[parts].f);
else
{
b[parts].buffer = (char*)realloc(b[parts].buffer, (b[parts].bufferctr + b[parts].bytectr) * sizeof(char));
memcpy(b[parts].buffer + b[parts].bufferctr, b[parts].bytes, b[parts].bytectr);
b[parts].bufferctr += b[parts].bytectr;
}
}
if(b[j].f)
fwrite(b[j].bytes, 1, b[j].bytectr, b[j].f);
else
{
b[j].buffer = (char*)realloc(b[j].buffer, (b[j].bufferctr + b[j].bytectr) * sizeof(char));
memcpy(b[j].buffer + b[j].bufferctr, b[j].bytes, b[j].bytectr);
b[j].bufferctr += b[j].bytectr;
}
b[j].bytectr = 0;
#if SPLITDEBUG
printf("@%i: reset bytectr\n", j);
#endif
}
}
}

i += (int)((totalbits - 1) / 8);
if((totalbits % 8) != 0)
{
inshifted += totalbits % 8;
if(inshifted % 8 == 0)
{
i += (inshifted - 8) / 8;
inshifted = 0;
}
else
i--;
}
}

for(j = 0; j < parts; j++)
{
if(b[j].bitctr > 0)
{
target = 0;
shifted = outbits - b[j].numbits;
precounted = 0;
for(k = 0; k < b[j].bitctr; k++)
{
#if SPLITDEBUG
printf("@%i: (%i=>%u) >> %i ; << %i\n", j, b[j].numbits, b[j].bits[k], b[j].shiftbits, shifted);
#endif
target |= (b[j].bits[k] << shifted);
shifted -= b[j].numbits;
if(shifted < 0)
{
b[j].bytes[b[j].bytectr] = target & 0xFF;
b[j].bytectr++;
shifted = outbits - b[j].numbits;
precounted++;
#if SPLITDEBUG
printf("@%i: [final-bytectr++]: %i {%i}\n", j, target & 0xFF, target);
#endif
target = target >> 8;
}
}
if(shifted != outbits - b[j].numbits)
{
#if SPLITDEBUG
printf("@%i: final-partialbyte: %i\n", j, target & 0xFF);
#endif
b[j].bytes[b[j].bytectr] = target & 0xFF;
b[j].bytectr++;
precounted++;
}
//b[j].bytectr += (int)((b[j].numbits * b[j].bitctr - 1) / totalbits) + 1 - precounted;
// FIXME: this may need a more general treatment
if(totalbits != 16)
b[j].bytectr += (int)((totalbits - 1) / 8);
#if SPLITDEBUG
printf("@%i: final-stuffed %i 'bits'/fragments; bytectr now %i\n", j, b[j].bitctr, b[j].bytectr);
#endif
b[j].bitctr = 0;
}
if(b[j].bytectr > 0)
{
if((j == 0) && (redundant))
{
#if SPLITDEBUG
printf(">> final-redundancy\n");
#endif
b[parts].bytectr = b[j].bytectr;
for(l = 0; l < b[parts].bytectr; l++)
{
b[parts].bytes[l] = 0;
for(k = 0; k < parts; k++)
b[parts].bytes[l] ^= b[k].bytes[l];
}
if(b[parts].f)
fwrite(b[parts].bytes, 1, b[parts].bytectr, b[parts].f);
else
{
b[parts].buffer = (char*)realloc(b[parts].buffer, (b[parts].bufferctr + b[parts].bytectr) * sizeof(char));
memcpy(b[parts].buffer + b[parts].bufferctr, b[parts].bytes, b[parts].bytectr);
b[parts].bufferctr += b[parts].bytectr;
}
}
if(b[j].f)
fwrite(b[j].bytes, 1, b[j].bytectr, b[j].f);
else
{
b[j].buffer = (char*)realloc(b[j].buffer, (b[j].bufferctr + b[j].bytectr) * sizeof(char));
memcpy(b[j].buffer + b[j].bufferctr, b[j].bytes, b[j].bytectr);
b[j].bufferctr += b[j].bytectr;
}
}
}

return 0;
}

int bitsplitbuffer(const char *inbuffer, ssize_t insize, char ***outbuffers, ssize_t **outsizes, int parts, int redundant, int bitwidth)
{
int ret;
int j;
bitsplit bs;

if((!inbuffer) || (parts <= 0)) return -1;
if(bitwidth < 1) return -1;

bs = bitsplitprepare(NULL, parts, redundant, bitwidth);
if(!bs.b) return -1;

*outbuffers = (char**)malloc((parts + redundant) * sizeof(char*));
*outsizes = (ssize_t*)malloc((parts + redundant) * sizeof(ssize_t));
for(j = 0; j < (parts + redundant); j++)
{
(*outbuffers)[j] = NULL;
(*outsizes)[j] = 0;
}

ret = bitsplitwork(inbuffer, insize, bs);

for(j = 0; j < (parts + redundant); j++)
{
(*outbuffers)[j] = bs.b[j].buffer;
(*outsizes)[j] = bs.b[j].bufferctr;
}

bitsplitfinish(bs);
return ret;
}

int bitjoinbuffer(const char **inbuffers, ssize_t *insizes, char **outbuffer, ssize_t *outsize, int parts, int bitwidth)
{
int ret;
bitsplit bs;

if((!inbuffers) || (parts <= 0)) return -1;

bs = bitsplitprepare(NULL, parts, 0, bitwidth);
if(!bs.b) return -1;

ret = bitjoinwork(inbuffers, insizes, bs);

*outbuffer = bs.b[0].buffer;
*outsize = bs.b[0].bufferctr;

bitsplitfinish(bs);
return ret;
}

int bitsplitfile(const char *filename, const char *directory, int parts, int redundant, int bitwidth)
{
FILE *f;
char buf[1024];
ssize_t size;
int ret;
bitsplit bs;

if((!filename) || (parts <= 0)) return -1;

f = fopen(filename, "r");
if(!f) return -1;

bs = bitsplitprepare(directory, parts, redundant, bitwidth);
if(!bs.b) return -1;

while(!feof(f))
{
size = fread(buf, 1, sizeof(buf), f);
#if SPLITDEBUG
printf("read %li bytes\n", size);
#endif

ret = bitsplitwork(buf, size, bs);
if(ret != 0)
{
fclose(f);
bitsplitfinish(bs);
return ret;
}
}

fclose(f);
bitsplitfinish(bs);
return 0;
}

int bitjoinfile(const char *filename, const char *directory, int parts, int bitwidth)
{
FILE *f, **dfs;
char **dbufs;
ssize_t *dsizes;
int ret;
//bitsplit bs;
int j;
char fname[1024];

if((!filename) || (parts <= 0)) return -1;

f = fopen(filename, "w");
if(!f) return -1;

dfs = (FILE**)malloc(parts * sizeof(FILE*));
dbufs = (char**)malloc(parts * sizeof(char**));
dsizes = (ssize_t*)malloc(parts * sizeof(ssize_t));

for(j = 0; j < parts; j++)
{
snprintf(fname, sizeof(fname), "%s/%i.stream", directory, j);
dfs[j] = fopen(fname, "r");
if(!dfs[j]) return -1;

dbufs[j] = (char*)malloc(1024 * sizeof(char));
}

//bs = bitsplitprepare(directory, parts, redundant, bitwidth);
//if(!bs.b) return -1;

while(!feof(dfs[0]))
{
for(j = 0; j < parts; j++)
{
dsizes[j] = fread(dbufs[j], 1, sizeof(dbufs[j]), dfs[j]);
#if SPLITDEBUG
printf("read %li bytes\n", dsizes[j]);
#endif
}

ret = -1;
//ret = bitsplitwork(buf, size, bs);
if(ret != 0)
{
for(j = 0; j < parts; j++)
fclose(dfs[j]);
fclose(f);
//bitsplitfinish(bs);
return ret;
}
}

for(j = 0; j < parts; j++)
fclose(dfs[j]);
fclose(f);
//bitsplitfinish(bs);
return 0;
}

please respond as soon as possible.

Age Calculator, Pass By Reference Problem.

Hi, fellow programmers.
I am programming about an age calculator.
It's simple:
1, get the input date 'today', check if its valid
2, get the input date 'birthday', check if it's valid and before 'today'
3, calculate the difference and output.
This is a assignment due tomorrow and I have written the most of it, just needs some debugging, mostly about pass by reference. I declared date1&date2 at main and I have no idea how to call the value of them if I want to calculate them at another function. I guess I should probably declare them at struct Date, but I am not sure.
I would really appreciate it if you guys could tell me what to do.
Code:
/************************************************************
 *
 * Project 4: How Old Are You Really?
 *
 * Author: xx
 * Date: 6 May 2015
 *
 * This is a program designed to calculates the difference 
 * between two dates, which will be expressed in terms of
 * years, months and days.
 *
 ***********************************************************/

#include <bjarne/std_lib_facilities.h>

struct Date {
    int month;
    int day;
    int year;
// Member functions
Date get_date();
Date get_birth_date();
bool is_valid_date(int year, int month, int day);
bool is_before(Date& date1, Date& date2);
Date calculate_age(Date& date1,Date& date2);
};

// Declaration
Date get_date();
Date get_birth_date();
bool is_valid_date(int year, int month, int day);
bool is_before(Date& date1, Date& date2);
Date calculate_age(Date& date1,Date& date2);

int main()
{
    Date date1 = get_date();
    Date date2 = get_birth_date();
    Date get_date();
    // Check if the date is correct
    if (! is_valid_date(year, month, day))
    error("Date is not valid.");
    // Run how old or not?
    char go_on;
    cout << "Would you like to see how old you are (y/n)?\n";
    cin >> go_on;
    if (go_on=='n'){
    cout << "You are so chicken!";
    return 0;}
    else if (go_on!='y')
    error("Please enter y for yes or n for no.");
    Date get_birth_date();
    // Is birthday valid as well?
    if (! is_valid_date(int year, int month, int day))
    error("Date is not valid.");
    // Is the birthday before 'today'?
    if (!(is_before(Date& date1, Date& date2)))
    error("Your birthday should not be later than today, terminator.");
    // Calculate and give the answer.
    Date calculate_age();
}

Date get_date()
{
    Date date1;
    cout << "Welcome to the age calculator!\n";
    cout << "Please enter today's date (mm/dd/yyyy): ";
    int m;
    int d;
    int y;
    // To ignore the '/' during reading
    char slash;
    cin >> m;
    date1.month = m;
    cin >> slash;
    cin >> d;
    date1.day = d;
    cin >> slash;
    cin >> y;
    date1.year = y;
    cout << "Date entered was "<< date1.month << "/" << date1.day << "/" << date1.year <<"\n";
}

Date get_birth_date()
{
    Date date2;
    cout << "Please enter your birth date (mm/dd/yyyy): "; 
    int m;
    int d;
    int y;
    // To ignore the '/' during reading
    char slash;
    cin >> m;
    date2.month = m;
    cin >> slash;
    cin >> d;
    date2.day = d;
    cin >> slash;
    cin >> y;
    date2.year = y;
    cout << "Your birthday is "<< date2.month << "/" << date2.day << "/" << date2.year <<"\n";
}

// Is date valid?
bool is_vaild_date(int year, int month, int day)
{
    if (day<0)
    return false;
    if (month<1 || month>12)
    return false;
    // Check if the date exists or not considering there are have
    // different days when month varies
    int days_in_month=31;
    switch (month){
    case 2:
    days_in_month=28;
    break;
    case 4: case 6: case 9: case 11:
    days_in_month=30;
    break;
    }
    if (days_in_month<day)
    return false;
    return true;
}

//Date check - is birthday before 'today'?
bool is_before(Date& date1, Date& date2)
{
    if (Date& date1.year<Date& date2.year)
    return false;
    else if (Date& date1.month<Date& date2.month)
    return false;
    else if (Date& date1.day< Date& date2.day)
    return false;
    return true;
}

// Calculation
Date calculate_age(Date& date1,Date& date2)
{
    Date date3;
    date3.day = date1.day - date2.day;
    date3.month = date1.month - date2.month;
    date3.year = date1.year - date2.month;
    if (date3.day<0){
        date3.day = 30 + date3.day;
        date3.month = date3.month - 1;
    }
    if (date3.month<0){
        date3.month = 12 + date3.day;
        date3.year = date3.year - 1;
    }
    cout <<"You are " << date3.year <<" years, "<< date3.month <<" months, and " << date3.day <<" days old.\n";
}

Rsync, Reliable "copy And Paste" Type Of Backup In Case Things Break?

What I did in windows was create images of my drive and restore them.

in linux I am running

Code:
rsync -aAXv --exclude={"/home/*","/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found"} /* /path/to/backup/folder

and this creates a folder for me with all my files, and apparently saves meta data like permissions and paths...

Since I'm using arch and things break sometimes,I'm booted into a CLI with errors and cannot figure my way out since I'm a noob... would I be able to just delete my entire root and replace it with the rsync backup without a problem?

Extract Info And Find/count Strings From Blocks Inside Text File

Hello

I have a text file which has blocks like
Code:
dir1/dir2/dir3/name_run_number1:
line1_run_number1_part1
line2_run_number1_part2
line3_run_number1_part3...

Each block is separated with a blank line and there is the ":" in the "header" of each one while each block carries the same "number1" after "run_" suffix
What I want to do is for each block, extract the "number1" as shown in the first line and then for the lines below count from 1-20 and give a message if a "partX" line is missing. Any bash or python would be fine

Thanks

Mutt Does Not Show Full Subject

I use following shell script to send email. But the subject of email always shows "This" instead of "This is L_1.R is finished". You may refer http://www.linuxquestions.org/questions/linux-newbie-8/how-to-define-variable-in-%60ssh%60-4175540566/
Code:
host_list=("c15-0330-01.ad.mtu.edu" "c15-0330-02.ad.mtu.edu" "c15-0330-03.ad.mtu.edu" "c15-0330-04.ad.mtu.edu")
program=("L_1" "L_2" "L_3" "L_4")
subject="The job is finished"
ssh -f c15-0330-01.ad.mtu.edu 'echo' "the job ${program[0]} is finished" '|' 'mutt "zwang10@mtu.edu" -s' "This is "${program[0]}".R is finished";

Python Ftplib

hello all,

please help me with python ftplib. i was trying to copy files from my linux machine to a windows server using ftplib. everything was working good. but i'm only able to copy files from the same directory the script is. how do i copy files from a different directory? i always get "file not found error message". here's my code :

Code:
tester_name = str (socket.gethostname())
def upload(ftp, file):
    ext = os.path.splitext(file)[1]
    if ext in (".txt", ".htm", ".html"):
        ftp.storlines("STOR " + file, open(file))
    else:
        ftp.storbinary("STOR " + file, open(file, "rb"), 1024)



parse_source_path = ('/path/to/where/i/go/')
parse_source_file_list = os.listdir(parse_source_path)

ftp = ftplib.FTP("server_IP")
ftp.login("username", "pass")

folder_list = []

ftp.dir(folder_list.append)

if str(tester_name) not in str(folder_list) :
    ftp.mkd("%s"%tester_name)
    ftp.cwd("%s"%tester_name)
    for files in parse_source_file_list :
        print files
        upload(ftp, files)


else :
    print "later"

"vconsole.conf" Show Unicode

Hi!

Here is mine configuration and I want make it show unicode(russian) in console, it works perfect in X11 but not when I logging into tty.

vconsole.conf
Code:
LOCALE="en_US.UTF-8"
KEYMAP="sv-latin1"
FONT_UNIMAP="lat1"
FONT_MAP="ISO8859-1"
CONSOLEFONT="ruscii_8x8"
HARDWARECLOCK="localtime"
TIMEZONE="Europe/Stockholm"
USECOLOR="yes"