Segmentation fault error (core dumped)

view story

http://ubuntuforums.org – I am trying to run the program below with g++ but its giving error segmentation fault (core dumped).. #include<stdio.h> int main(int argc, char *argv[]) { char ch; int count=0,i=0; char c[10]; FILE *fptr; fptr=fopen("res.txt","r"); printf("\nContents of the File is:"); while((ch=fgetc(fptr))!=EOF) { if(ch ==' ') { i=0; while(ch!='\n') { c[i]=ch; i++; } printf("%s :",c); } } fclose(fptr); //getch(); return 0; } res.txt file: big-O: 17850 big-O: 80800 big-O: (Hardware)