c - Segmentation fault when checking if (char == '\n') -


i have been struggling on hour , can't seem find out why error.

int  inp, count; char numbuff[21];  count = 0; while((inp=getchar()) != eof) { // value (last field)     printf("input '%c'\n", inp);     if (inp == '\n') break;     if (inp == ' ') {         continue;     }     numbuff[count++] = inp;     printf("go through loop\n"); } printf("out!"); numbuff[count] = '\0'; 

if input 1013 following

input '1' go through loop input '0' go through loop input '1' go through loop input '3' go through loop input ' ' segmentation fault (core dumped) 

the thing can gather is failing when check if inp == '\n' why? moved go through loop printf after check if inp == '\n' , never reached 1 either know occurring there.

you gather error in loop, how know? did try using debugger - useful tool pinpoint crash occurs , allow examine state of program.

dollars donuts crash occurs in code after loop. reason not see "out" message because don't print newline standard library buffers output.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -