Whenever I use the c function gets() to input a string, then try to parse the string with a pointer in a loop using pointer != '\0' as the loop termination condition, the pointer always goes way out of the bounds of the string anyhow.
This code outputs all kinds of stuff outside of the array of chars. It does the exact same thing if I useCode:#include <stdio.h> #define string_terminator '\0' #define MAX_CHARS 80 void main() { char input[MAX_CHARS]; char *ptr_to_string = input; gets ( input ); for (input; input != string_terminator; input++) puts ( input );
What am I doing wrong?Code:for (ptr_to_string; ptr_to_string != string_terminator; ptr_to_string++)



Adv Reply





Bookmarks