Change case in C language

Change case in C language

I want to right in .dat file through structure.For this i have defined following:

struct student //structure defination
    {
    char name[25];
    char course[25];
    char rollNum[20];    
    };


(A) in rollNum field i am taking input in two formates.
 1. 1234
 2. A1234/a1234

(B)in second formate i always wants to write data in upper case for example
   If user is typing b5678 ,i want to store as B5678.

(C)for input i am using these statements:

  printf("\n\tEnter Roll number (Ex.1234 or a123)\n");
           scanf("%s",s.rollNum);


(D)for writing on file i am using these statements:


fprintf(fp,"%s %s %s \n" ,s.rollNum,s.name,s.course);


(E)Can you please tell how is it possible to change case before writing in .dat file
I tried through toupper() and strupr() but having typecasting error.

Thanks in advance
Ankita
View Answers

April 6, 2011 at 4:47 PM

Post your code.


April 7, 2011 at 1:37 AM

Code is

    #include 
    #include 
    #include 
    #include 
    int isValid(char[],char[]);//function declaration

    struct student //structure defination
    {
    char name[25];
    char course[25];
    char rollNum[20];    
    };

    //isvalid function for checking valid rollnumber pattren and name

    int isValid(char str[],char str1[]){
    int i=0,j=0,flag=0,flag1=0;

    for(i=0;i= 'A' && str[i] <= 'Z') ||(str[i] >= 'a' && str[i] <= 'z'))
           flag=0;
           else
           if((str[i]>='0'&&str[i]<='9')||((str[i]>='A'&&str[i]<='Z')||(str[i]>='a'&&str[i]<='z'))) 
           flag=1;  

          }  /*checking for valid name only characters*/
          for(j=0;j='A'&&str1[j]<='Z')||(str1[j]>='a'&&str1[j]<='z'))
           flag1=1;
           else
           flag1=0;  
           }
    return (flag && flag1);
    }

       //main function
    int main()
    {
    int choice,rCheck=0,k=0,flag;
    FILE *fp;
    struct student s;
    char loop,search[20],rollNum1[25];


    //open file in append mode
    fp=fopen("Student.dat","a+");

    if(fp==NULL)
    {
    printf("FILE CAN'T OPEN.\n");
    exit(1);
    }
    printf("\n\tOUT PUT 2\n");

    //menu
    do
    {flag=1;
    printf("\n\t1.Add Record\n");
    printf("\t2.Display Records\n");
    printf("\t3.EXIT\n");
    printf("\tEnter your choice...\n");
    scanf("%d",&choice);


    switch(choice)
    {

    //Add Record in file
    int k;
    case 1:printf("\n\tEnter Roll number (Ex.1234 or a123)\n");

//Here i want to change case
//...........................................

           scanf("%s",s.rollNum);

//.....................................
          fseek(fp,0,SEEK_SET);

           /*searching rollnumber in file for avoiding duplicate rollnum*/
           while(fscanf(fp,"%s",search)!=EOF){                                      
           if(strcmp(search,s.rollNum)==0){
           printf("This roll number already exist!!!!!");
           flag=0;break;}}

            /* rollnumber not exist then add data*/ 
           if(flag!=0){ 
           printf("\n\tEnter name and subject\n");
           scanf("\n\t%s %s",s.name,s.course);
           rCheck=isValid(s.rollNum,s.name);
           if(rCheck==1)        
           fprintf(fp,"%s %s %s \n" ,s.rollNum,s.name,s.course);
           else
           printf("\n\n!!!!Enter correct rollnumber and Name!!!!!");
           }
           break;

    //Display records from begining

   case 2:fseek(fp,0,SEEK_SET);
          printf("\n\tROLLNUMBER\tNAME\t\tCOURSE\n");
          while(fscanf(fp,"%s %s %s",s.rollNum,s.name,s.course)!=EOF)
          printf("\n\n\t%s \t\t%5s \t\t%s \n",s.rollNum,s.name,s.course);
          break;

    //exit
    case 3:exit(1);
    /*default*/
    default:printf("\n\n\t\a    !!!!!! WARNING !!!!! \a\n\t");
            printf("\n\t\a!!!!!! Please enter valid choice !!!!! \n\t"); /*default case*/
            system("pause");
            exit(1);
    }

     printf("\n\n\t Do you want to continue (Y/N) : ");
     loop=getche();

    }while(loop=='y'||loop=='Y');


    //close file
    fclose(fp);

    }

April 11, 2011 at 11:25 PM

Can anybody help me in solving this question?









Related Tutorials/Questions & Answers:
Change case in C language
Change case in C language  I want to right in .dat file through... how is it possible to change case before writing in .dat file I tried through... (B)in second formate i always wants to write data in upper case for example
C Language
C Language  What's the right declaration for main()? Is void main() correct? in C language ? please help me sir ! Thank You
Advertisements
ModuleNotFoundError: No module named 'change_case'
ModuleNotFoundError: No module named 'change_case'  Hi, My Python... 'change_case' How to remove the ModuleNotFoundError: No module named 'change_case' error? Thanks   Hi, In your python environment
C language
C language  i want that when i hit any key only * to be print not the hit key in c language   The given example will display aestricks on hitting any key. #include "stdio.h" #include "conio.h" #include "ctype.h" int
C Language
C Language  Respected sir, Why does sizeof report a larger size than I expect for a structure type, as if there were padding at the end? help me sir
C Language
C Language  Respected Sir, How can I determine the byte offset of a field within a structure? How can I access structure fields by name at run time? please help me sir . Thank you sir
c language code
c language code  Dear Sir, Could you send me the c language codings for BOOK BANK
c-language pointer functions
c-language pointer functions  what is the execution process of character pointer functions with example
hotel management programme in c language?
hotel management programme in c language?  hotel management programme in c language
about a program in c language
about a program in c language   Write a program that inputs five different integers from the keyboard, then print the sum, the product, the smallest and the largest of these numbers. Use only single selection form of if statement
PHP Change Case
PHP String Change Case: In this current tutorial we will study how to change a string from normal text to all lower case text, to all upper case text... every first character of each word to uppercase. ADS_TO_REPLACE_1 PHP String Change
logic for c language
logic for c language  01 02 03 04 05 06 20 21 22 23 24 07 19 32 33 34 25 08 18 31 36 35 26 09 17 30 29 28 27 10 16 15 14 13 12 11
C Language - Java Beginners
C Language  1. What are extension files? Give examples. 2. What is operating system? What are the different types available? 3. What is the purpose of operating system? 4. What is the function of operating system? 5
Case-insensitive search using Hibernate Query Language(HQL).
Case-insensitive search using Hibernate Query Language(HQL).  What is Case-insensitive search using Hibernate Query Language
Change language according to the locale
Change language according to the locale       This Example shows you how to change language according to the locale. In the code given below we have changed
write a program to use for loop print **********========== in c language
write a program to use for loop print **********========== in c language  write a program to use for loop print **========== in c language
C++ programming language - Java Beginners
C++ programming language  int main() { int i = 1, c = 0, sum = 1,j ; scanf("%d", &j); while (i <= j) { sum = sum + (i /3+i/5); printf
c programming language - Java Beginners
c programming language  int main() { int i = 1, c = 0, sum = 1,j ; scanf("%d", &j); while (i <= j) { sum = sum + (i /3+i/5); printf("%d
Sample code for An ASCII Encryption and Decryption code in C-language only.
Sample code for An ASCII Encryption and Decryption code in C-language only..., add a word space. Change word by word until the end of the message which is later... in ASCII format and only in C (NOT EVEN C++). Thank you.Please if possible post
C language-qsort and bsearch function - Ajax
C language-qsort and bsearch function  Explain qsort and bsearch...() #include #include #include #include char alpha[] = {'a','b','c...); if(p) printf(" %c is in alphabet\n", *p); else printf("is not in alphabet\n
C Language - Design concepts & design patterns
C Language  What is meant by %u in printf statement in c? for example,%d means integer value,like that what is %u?  Hi Friend, %u is used to print an unsigned integer. Unsigned integers are non-negative numbers
Main function parameter in C language - Ajax
Main function parameter in C language  Please let me know how... of fgetpos(): #include #include int main () { FILE * pFile; int c...==NULL) perror ("Error opening file"); else { c = fgetc (pFile
Write a C language program to read two matrices and multiply them?
Write a C language program to read two matrices and multiply them?  Write a C language program to read two matrices and multiply them?   Here is an example of multiplying two matrices using C language. #include <
c++
c++  i use turbo c++...i want to change the background color...what is the command for it and the header file used
c++
c++  i use turbo c++...i want to change the background color...what is the command for it and the header file used
c++
c++  i use turbo c++...i want to change the background color...what is the command for it and the header file used
Ask C/C++ Questions online
language, but both the languages are popular among programmers. C is a general purpose programming language that can run on most of the platforms. C is used... Bell Laboratory while C++ is a popular object oriented programming language
Objective C Introduction
programming language. Objective C is very old programming language... in early 1980's. The Objective-C language is designed to enable a easier... to the C language. Objective C takes best features from C and smalltalk. Objective C
C++
C++  How can i write this in dev c
C++
C++  How can i write this in dev c
c#
c#  how to find out the size of the BMP image in C
c++
c++  use a prgrm as an example to xplain-: a)class b)object c)message d)cope resolution operator
bsearch() function in C
bsearch() function in C Programming Language This section demonstrates the use bsearch() function in C. This searches function the given key in the array...[] = { 'a', 'b', 'c', 'd' }; int comp(const void *a, const void
c++
c++  write a programme that calculates the area and circumference of a rectangle
c#
c#  how to find out the size of the BMP image
C++
C++  dear sir How to create windows form application for login screen using C++? USER Name -TESTADMIN Password -testuser
c++
c++  differenciate btw.-a)local & public variables b)pre-defined & user defined functions c)fnctn prototype,defination & fnctn code.use code examples
c++
c++  differenciate btw.-a)local & public variables b)pre-defined & user defined functions c)fnctn prototype,defination & fnctn code.use code examples
C++
C++  differenciate btw.-a)local & public variables b)pre-defined & user defined functions c)fnctn prototype,defination & fnctn code.use code examples
XML is case-sensitive
XML is case-sensitive  hello, can some body can tell me that Is XML case-sensitive or not ?   HELLO MAN,ADS_TO_REPLACE_1 YEAH, XML IS A CASE SENSITIVE LANGUAGE
C++
C++  Describe the principle advantages of deploying a linked list versus a static array when implementing a Queue or a Stack
c++
c++  write a prgrm tht accepts 3 integer values,then with a function to swap the values
C++
C++  Trace the bubble sort using the following integers,which represent the elements in an array. 5,7,3,8,6,7,3
C++
C++  I have been asked to write a programme that gets five values,gets the sum,average and product please help me
C#
C#  i need a code that will make program perform the basic operations upon the data Listview save, update and cancel
Difference between Java and C++
exist in C language. C++ is a middle level programming language... language. Originally named as "C with classes", but later it was renamed to C++ in 1983. C++ is a general purpose programming language
c++
c++  write a program that gets a key or character from the keyboard and displays it ASII code in decimal, hexadecimal and binary form.It must also give a description of the key pressed
c++
c++  write a prgrm tht calculates the surface area of a cylinder.the prgrm shld find the circumfrance and have a function that calculates the fadius and another to calculate the surface area
C++
C++  write a prgrm tht gets five values,gets the sum,average &...; #include <conio.h> void main() { clrscr(); int a,b,c,d,e,sum; float average...;>b>>c>>d>>e; sum=a+b+c+d+e; average=sum/5; product=a*b*c*d
c++
c++  .write a program that accepts 5 subjects of a student,it should have a function to calculate the average & another function to grade.grade should be as follows-<40=E,40-49=D,50-59=C,60-69=B & >70

Ads