Thread: how to change all the upper and lower letters from text file?

  1. #1
    Registered User
    Join Date
    Nov 2010
    Posts
    20

    how to change all the upper and lower letters from text file?

    how to change all the upper and lower letters from text file?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    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.

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    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.

  4. #4
    Registered User
    Join Date
    Nov 2010
    Posts
    20
    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;
    }
    i ques it's wrong?
    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++;  
       }
    OR i use this?

  5. #5
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    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.

  6. #6
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    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.

  7. #7
    Registered User
    Join Date
    Nov 2010
    Posts
    20
    I appreciate your help, it was helpful, i made that program, now it's works fine

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Text files and validation
    By Futomara in forum C Programming
    Replies: 34
    Last Post: 11-02-2010, 12:10 PM
  2. to lower or to upper that is the question!
    By verbity in forum C++ Programming
    Replies: 20
    Last Post: 04-25-2007, 06:42 PM
  3. help...Lower and Upper case problem only
    By j4k50n in forum C Programming
    Replies: 9
    Last Post: 04-19-2007, 12:39 AM
  4. Function is called and I am trying to open a file
    By tommy69 in forum C Programming
    Replies: 88
    Last Post: 05-06-2004, 08:33 AM
  5. Merge sort please
    By vasanth in forum C Programming
    Replies: 2
    Last Post: 11-09-2003, 12:09 PM