how to change all the upper and lower letters from text file?
how to change all the upper and lower letters from text file?
fgets() to read lines.
toupper() and tolower() to change case.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Use a loop to scan over each letter of the text file. Inside the loop, use:
if(character > 'Z') //it's a lowercase letter
character = toupper(character);
and repeat with similar logic (all based on the (probably ascii), value of the characters on your system), for converting uppercase letters to lowercase.
You will need to add ctype.h at the top of your program.
i ques it's wrong?Code:# include <stdio.h> # include <stdlib.h> # include <string.h> int main() { FILE *fp; int fscanf(FILE *fp, const char *str, ...); char *str( char *str); char str[80]; if ((fp=fopen("failas.txt","rb+"))==NULL) { printf("Klaida atidarant faila \n"); exit(1); } else { fscanf(fp,"%s", &str); char str[80]; strupr(str); while(!feof(fp)); } { fscanf(fp,"%s",&str); printf("%-5s \n", str); } { fclose(fp); } system("pause"); return 0; }
OR i use this?Code:void longest_word(FILE *f,FILE *f1) { char data[2000]; int i,len=0,len1=0,k=0; for(i=0;i<2000;i++) { if(data[i]==EOF) break; data[i]=fgetc(f); if((data[i]>='a'&&data[i]<='z')||(data[i]>='A'&&data[i]<='Z')) { len++;} else if(len>len1) {len1=len; k = i-len; len=0;} } for(i=k;i<k+len1;i++) fprintf(f1,"%c",data[i]); i++; }
You're going to use stolen code that finds the longest word in a line, to change text from upper to lower case?
Nobody wants to help a cheat and a thief. Spend some time working on your own code and you might learn something, like the difference between letter cases and word lengths.
Wow... classic tactical error.
Alionas... this is called "scoop and poop coding" and I'm pretty sure you can now appreciate why it's a bad thing to do.
Enjoy your programming career... short though it may be.
I appreciate your help, it was helpful, i made that program, now it's works fine