Use of while

This is a discussion on Use of while within the C Programming forums, part of the General Programming Boards category; Is this a valid use of the while() command? char *p1; char name[100]; . . . while((p1=strchr(name,','))!=NULL) memmove(p1,p1+1,strlen(p1)); My compiler ...

  1. #1
    Unregistered
    Guest

    Use of while

    Is this a valid use of the while() command?

    char *p1;
    char name[100];
    .
    .
    .
    while((p1=strchr(name,','))!=NULL) memmove(p1,p1+1,strlen(p1));

    My compiler compiles fine, but when I execute it, the brackettes of other statements get all screwed up and the program flow/logic is fragged. Doing the following works as expected:

    while((p1=strchr(name,','))!=NULL) {
    memmove(p1,p1+1,strlen(p1));
    }

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    Both loops are valid and correct. Could you show some more of your code? Perferably something we can compile and play with?

    -Prelude
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21