I am reading txt data in binary. But I am not sure how to break the lines up, based on "\n", after reading the file content into a buffer. Any hints?
Type: Posts; User: 911help
I am reading txt data in binary. But I am not sure how to break the lines up, based on "\n", after reading the file content into a buffer. Any hints?
read txt file as binary then convert it back to text inside a function? is this possible at all? if so, how?
1) I need to escape the "%Y%m%d%H%i%S" in sprintf.
2) In sprintf, I need to fill %s with datestr value.
I tried the following:
char buf[1024], datestr[256];
strcpy(datestr, "20071231");...
So what's the final verdict?
Program memory is copied, not function memory stack, even when fork is called from within a function?
Thanks, encouragement helped. perror helped solve the problem. I was using relative path to read the conf file in progB and I changed to absolute path to conf file in progB. It's working now.
...
When you fork a process, what memory is passed to the forked process (whole program memory or in the above example, only "call me" function's memory stack is passed to the forked process?)
I did print the getcwd inside the forked child before execl command, it points to /home/joe/myprogs. Which correct by the way.
I think forking to call another program has to do with file...
proga is located at the root of folder:
myprogs
progb is located in folder "server", which is inside "myprogs" folder.
myprogs:
server:
In proga, I read setup file using . And then have...
Now the program runs independently on its own. If I just run progb, it reads the config file and completes as expected. That semi-colon caused bitter headache. Thank you for it.
But I am back...
FILE *open
and
FILE * open
are same thing. Space between * open makes any different?
I did this and not reading the ./server.conf file now. Permission is looking good on the file:
if((configfile= fopen("./server.conf", "r"))==NULL);{
syslog(LOG_INFO,"%s unable to read config...
I have question about this piece of code fragment. When I run a c-programb on its own, it works fine.
But when I fork this program from another program, I get this program to do segfault at...
>1. If any of the exit() are called, there is no return to main.
Salem, I don't understand what you mean by no return to main.
For example, main had other statements to execute after "call_me"...
void call_me(){
pid_t child;
if((child=fork()) < 0){
exit(-1);
}
else if(child==0){
execl("./someexample","./someexample",(char*)0);
exit(1);
}
In C program I have a function:
void eg1()
{
if (i==1){
exit(1)
}
}
million thanks for everyone.
Salem, I tried fork as you mentioned on Daniweb. It gave a problem. I wanted to try system call. This is also giving me problems.
Can someone help with this? No one had done zipping stuff...
I don't know what the problem here. I tried to gzip the file using system(). Text file is there, but never get gzipped. I get garbage printed out on the console soon as I call system();.
Do I...
I am using gdb to walk through the break points.
printf("print before system(cmd) call\n");
pid_err=system(cmd); //Problem here: it's printing garbage on the screen
printf("print after...
Can a call to system be string variable or actual string in double quoted form?
sprintf(cmd, "cp %d.txt %d.csv",i,i);
pid_err=system(cmd); //Problem here: it's printing garbage on the...
Rather than:
c=open("./server.conf",O_RDONLY);
read(c,buf,sizeof buf);
close(c);
Change it to this:
c=open("./server.conf",O_RDONLY);
read(c,buf,99);
Sorry my bad it should of been:
char buf[100];
char *buf1;
I am not sure why I get segfault or 0 here.
num=atoi(strtok(NULL,"=")); //I am getting segfault here or it is giving out 0.
Can...
What I need to do is set num = 2 as it specified in server.conf. At num=atoi(strtok(NULL,"=")); I am getting segfault there or it is giving out 0. I am running linux and gcc 4.1.2.
server.conf:
...