Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners Change case in C language
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


ankita anchliya
Change case in C language
3 Answer(s)      3 years and 9 months ago
Posted in : Java Beginners


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

Advertisement
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
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
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. PHP String Change Case Example
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
hotel management programme in c language?
hotel management programme in c language?  hotel management programme in c 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
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
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
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 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
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 - 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
Hibernate Query Language
Hibernate Query Language       Hibernate Query Language or HQL for short is extremely powerful query language. HQL is much like SQL  and are case-insensitive, except
c#
c#  how to find out the size of the BMP image in C
C++
C++  How can i write this in dev c
C++
C++  How can i write this in dev c
c++
c++  use a prgrm as an example to xplain-: a)class b)object c)message d)cope resolution operator
Advertisements
 

 

 

DMCA.com