Search:

Type: Posts; User: 911help

Search: Search took 0.01 seconds.

  1. fread bytes of data from txt file: break on newline

    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?
  2. Replies
    2
    Views
    2,831

    read txt file as binary then convert to text

    read txt file as binary then convert it back to text inside a function? is this possible at all? if so, how?
  3. Replies
    2
    Views
    4,211

    sprintf and escaping "", %

    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");...
  4. So what's the final verdict? Program memory is...

    So what's the final verdict?

    Program memory is copied, not function memory stack, even when fork is called from within a function?
  5. Replies
    10
    Views
    2,983

    Thanks, encouragement helped. perror helped...

    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.
    ...
  6. When you fork a process, what memory is passed...

    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?)
  7. Replies
    10
    Views
    2,983

    I did print the getcwd inside the forked child...

    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...
  8. Replies
    10
    Views
    2,983

    proga is located at the root of folder: myprogs...

    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...
  9. Replies
    10
    Views
    2,983

    Now the program runs independently on its own. ...

    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...
  10. Replies
    4
    Views
    979

    pointer question: * space name

    FILE *open

    and

    FILE * open

    are same thing. Space between * open makes any different?
  11. Replies
    10
    Views
    2,983

    I did this and not reading the ./server.conf file...

    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...
  12. Replies
    10
    Views
    2,983

    weird segfault in fgets in process

    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...
  13. >1. If any of the exit() are called, there is no...

    >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"...
  14. handling exits: main calls a function which creates processes

    void call_me(){
    pid_t child;

    if((child=fork()) < 0){
    exit(-1);
    }
    else if(child==0){
    execl("./someexample","./someexample",(char*)0);
    exit(1);
    }
  15. Replies
    3
    Views
    2,398

    calling functions: exit and return

    In C program I have a function:


    void eg1()
    {
    if (i==1){
    exit(1)
    }
    }
  16. Replies
    8
    Views
    3,868

    million thanks for everyone.

    million thanks for everyone.
  17. Replies
    8
    Views
    3,868

    Salem, I tried fork as you mentioned on Daniweb. ...

    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...
  18. Replies
    8
    Views
    3,868

    I don't know what the problem here. I tried to...

    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...
  19. Replies
    8
    Views
    3,868

    I am using gdb to walk through the break points. ...

    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...
  20. Replies
    8
    Views
    3,868

    Calling system with a string variable

    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...
  21. Replies
    6
    Views
    1,010

    Rather than: c=open("./server.conf",O_RDONLY);...

    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);
  22. Replies
    6
    Views
    1,010

    Sorry my bad it should of been: char buf[100];...

    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...
  23. Replies
    6
    Views
    1,010

    Tokenizing the string problem

    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:
    ...
Results 1 to 23 of 23