c - while compiling below code am getting segmentation fault can you spot me the error for me -


#include<stdio.h> #include<ctype.h> void main() {     file *fp1,*fp2,*fp3;     char a[100],b;     int i=0,j=0;     fp1=fopen("names.txt","r");     fp2=fopen("names.txt","w");     i=0;         {         b=fgetc(fp1);        b=toupper(b);        a[i]=b;         i++;     } while(b!=eof);     i=0;         {         fputc(a[i],fp2);         i++;     }while(a[i]!=eof);     fclose(fp1);     fclose(fp2);     fclose(fp3); } 

am getting segmentation fault while compiling code can u plzz me spotting error error like"line 2:segmentation fault "

you need learn how debug. either learn how use debugger, or if haven't got patience, put debug prints in code see how far getting. example:

fprintf(stderr, "%d\n", i); 

that tell something. find error pretty quickly.

my guesses are:

  1. your file bigger 100 characters.
  2. b should int , should not store in array.
  3. the second loop should not end-of-file, should use count of number of characters read.
  4. you closing fp3 haven't opened it.

but again, basic stuff. need learn basic debugging.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -