Problem filehandling in C | Sololearn: Learn to code for FREE!

0

Problem filehandling in C

Problem file handling in C visph it's read the text and doesn't calcul the number of the words Then show a "segmentation fault". I'm beginner with using file in C, I didn't find where's the problem i hope you can help , And thank you The code: https://code.sololearn.com/cdgqkKb3hNAA/?ref=app

5/27/2021 7:37:19 PM

マナール

22 Answers

New Answer

0

bonne chance ;)

+3

I was rather meaning a link to a sololearn code playground, where we can test and run the code ^^ I just tried to access to your google drive, but it required me to be connected, and I don't want to be tracked by google ;P

+2

マナール translate the comments in your code (and save it, as same project, not as a new one): this will help those who will look at it ;)

+2

Define "special characters".

+2

To determine if a character is lowercase use islower(), to determine if a character is uppercase use isupper(). I have no idea what you consider a "special character" but there are functions that test for isblank(), ispunct(), isdigit(), isgraph() and iscntrl(). All of these are in <ctypes.h> https://www.cplusplus.com/reference/cctype/ To read a char in from a file use fgetc(), or To read a char in from a file use fscanf() with the %c format string To read a string (word) in from a file use fscanf(). with the %s format string To read a line of text from a file use fgets() All of the above are in <stdio.h> To test the length of a string (word) use strlen() To test if a string contains a substring (e.g. "en") use strstr() To test if string ends with a substring (e.g. "ent") use strcmp() on the last n characters of a string, where n is the number of chars you wish to test. All of the above are in <string.h> A number of your functions have an argument of FILE* but it is unnecessary as you open and close the file in the function. A local FILE* will do the job. Why are you using a file anyway? You limit the number of characters to 100 with the global variable "n" and you read it in from the keyboard as a string. You can perform all of these operations on that string.

+1

well, if it read a file, you cannot simply run it in sololearn playground... however, we could try to explore and debug it more easily :) not sure I could help, but maybe someone else: you'll get more chances to receive help by posting a code playground link anyway... or be a little if not a lot more patient ^^

+1

If I knew what you were trying to do it would be quicker to rewrite the code rather than trying to fix this. When writing a large piece of code like this it is advisable to build it up in stages testing each function as you go along rather than be confronted with a huge number of problems like this. It's going to take me a while to translate the comments and figure out what you are trying to do before I can start working on it. Looking at your profile I can see that you have completed 0% of the C course and 12% of the C++ course. You appear to be out of your depth here.

+1

Martin Taylor, マナール oh, yes, I wanted to add to translate the comments in my last advises, but I finally forgot that point, as french doesn't disturb me ^^

+1

Martin Taylor 🔴A text file 🔴 I want program 🔴Which allows you to count the number of words in this text 🔴 Which displays the number of uppercase characters, the number of lowercase characters, and the number of special characters 🔴 Which displays words of length equal to 4 🔴 Which displays the words containing the string "en" 🔴 Which displays words that end with "ent"

0

void nombre_majuscule_miniscule_caractere_speciaux(FILE*ftext,char text[n]) {int majuscule,miniscule,speciaux; //open fichier pour lire ftext = fopen(text, "r"); //nombre des mot majuscule=miniscule=speciaux=0; while ((ftext=fgetc(ftext))!= EOF) {/* calculer nombre de mot */ if (text>='A' &&text<='Z') // nombre des majescule dans le text majuscule++; else if (text>='a' &&text<='b') // nombre des miniscule dans le text miniscule++; else if(text!=' ') //nombre des caracters speciaux speciaux++; } /* affichage de nombre de caracteres majuscule */ printf("\n"); printf("nombre des caracteres majuscule dans le text = %d\n",majuscule); /* affichage de nombre de caracteres miniscule */ printf("\n"); printf("nombre des caracteres miniscule dans le text = %d\n",miniscule);

0

could you provide a link to your code and describe what's the problem you're facing (rather than giving the code in description and post)?

0

visph https://drive.google.com/file/d/12XK9JV1DAbgL84D-ZhikRXXwjG_VWq11/view?usp=drivesdk

0

visph it's read the text and doesn't calcul the number of the words Then show a "segmentation fault". I'm beginner with using file in C, I didn't find where's the problem i hope you can help , And thank you

0

visph oh sorry I'm new in this app 😁😁 you mean like this?? https://code.sololearn.com/cdgqkKb3hNAA/?ref=app

0

yes :) I will take a look...

0

visph it's Okey I still have too much things to learn

0

sorry, it's above my skill in c/c++ I cannot help you :( anyway, be patient: probably someone could help you ;) however, you could clean your thread to increase your chances, by updating the title (mention that it's about file handling), the tags (mention also at least 'file' along with 'c') and the description (delete the code, paste your two links, and put at least the description you've made after posting the first link), and finally delete your first post...

0

visph ok Thank you 🥰🥰 I will do that

0

There are rather a lot of errors in this code: timeout: the monitored command dumped core ./Playground/runner.sh: line 103: 17 Segmentation fault timeout "$runtime" "$output" - < "/usercode/inputFile" nt-conversion] 12 | while ((ftext=fgetc(ftext))!= EOF) ./Playground/file0.c:12:32: warning: comparison between pointer and integer 15 | if (text==' ' ||text=='\0'||text=='.') ./Playground/file0.c:15:29: warning: comparison between pointer and zero character constant [-Wpointer-compare] 15 | if (text==' ' ||text=='\0'||text=='.') ./Playground/file0.c:15:25: note: did you mean to dereference the pointer? 15 | if (text==' ' ||text=='\0'||text=='.') ./Playground/file0.c:15:41: warning: comparison between pointer and integer 15 | if (text==' ' ||text=='\0'||text=='.') ./Playground/file0.c: In function 'nombre_majuscule_miniscule_caractere_speciaux': ./Playground/file0.c:32:18: warning: assignment to 'FILE *' from 'int' makes pointer from integer without a cast [-Wint-conversion] 32 | while ((ftext=fgetc(ftext))!= EOF) ./Playground/file0.c:34:17: warning: comparison between pointer and integer 34 | if (text>='A' &&text<='Z') ./Playground/file0.c:38:19: warning: comparison between pointer and integer 38 | if (text>='a' &&text<='b') ./Playground/file0.c:42:20: warning: comparison between pointer and integer 42 | if(text!=' ') ./Playground/file0.c: In function 'nomber_mot_len4': ./Playground/file0.c:68:16: warning: comparison between pointer and integer 68 | if(text>='A' &&text<='Z') ./Playground/file0.c:70:22: warning: comparison between pointer and integer 70 | else if (text>='a' &&text<='b') ./Playground/file0.c:62:9: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else] 62 | {if(text[i]==' ') ./Playground/file0.c: In function 'trouve_en': ./Playground/file0.c:79:22: warning: suggest parentheses around '&&' within '||' [-Wparentheses]

0

Martin Taylor Yeah it a big mess Actually i studying C language but i didn't practice in this app I will give you the notes of what i want to do