Home Answers Viewqa Java-Beginners Change case in C language

 
 


ankita anchliya
Change case in C language
3 Answer(s)      2 years and a month 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
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 Pages:
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
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
C Language  What's the right declaration for main()? Is void main() correct? in C language ? please help me sir ! Thank You
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 and C++ books-page2
C and C++ books-page2       The Advice & Warning for C Tutorials  C and C++ are widely promoted as ideal portable, fast, and - in the case of C++ - "object
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
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
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
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
C and C++ books-page10
; The programming language C As a programming language, C is rather... offers an introduction to the C++ programming language. It is a guide for C/C... should realize that extensive knowledge of the C programming language is actually
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
C and C++ books
C and C++ are widely promoted as ideal portable, fast, and - in the case of C...-fashioned C string) and in the second case a zero-terminated array of XMLCh's... As a programming language, C is rather like Pascal or Fortran. Values are stored
Java vs. C
++, you already know a lot of Java. The Java language is based mostly on C and C++. You'll see that a lot of the basic language elements, for example... is a small language, smaller than C++, and perhaps smaller than C. This may be true
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
C++Tutorials
++ is a programming language substantially different from C. Many see C++ as "a better C than... to teach C++ in a way that makes use of what the language can offer. C++ shares... to speed on that language.      C++ Annotations
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
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
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 and C++ books-page12
to give you a general overview of the C programming language. Although much... program Note C is a relatively small language, but one which wears well. C's... have programmed in assembly language, you'll probably find C very natural
C Tutorials
.    C Break with Switch statement The switch case... defined in C language have a base address attached to it.   ... C Tutorials      
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
XML is case-sensitive
XML is case-sensitive  hello, can some body can tell me that Is XML case-sensitive or not ?   HELLO MAN, YEAH, XML IS A CASE SENSITIVE LANGUAGE
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
Java is case sensitive
Java is case sensitive  hello, Why Java is case sensitive?   hii, Java is Platform Independent Language, so its used widely in very big... that huge no of variables,Java is Case Sensitive
C/C++ Programming Books
; Object-Oriented Programming and The Objective C Language... language like C++. In this ebook we give you a good start for a programming standard... in the dictionary.Variables are the "words" for the C language. In a program, variables have
using case in update statement
using case in update statement  i want to use case in update clause. i have used case in select stmt referring answer in this site. but the same syntax is not working for update stmt.my problem is update emp set case deptno
Switch case + condition??
Switch case + condition??  I try to use a switch case with condition...(Command c, Displayable d) { String label = c.getLabel...(down.getSelectedIndex()) { case 0: Tambo(); if( label.equals
Case study of xyz.com
Case study of xyz.com  Scenario: Online Shopping Portal XYZ.com wants to create an online shopping portal for managing its registered customers... the functionality using the server side scripting language, PHP. Integrate all
ipms case study
ipms case study  IPMS Case Study ABC company is a small software company. Due to a good delivery track record, the company started to get more... Change Requests Prepare Implementation Plan Coding Code validation Prepare
dth case study
dth case study  DTH Case Study BNM Corp is a new player in the DTH (Direct to Home) satellite TV business in India. It has a sister concern BNV Corp... on the software solution. The manager alone can make change to the rates and add
broad band case study
broad band case study  Broadband Case Study LKV Company is a new firm... and also change the plans. The customer can call anytime to en-quire about his details validity date, usage, validity expiry (in case of prepaid customer
case study of xyz.com
case study of xyz.com  After learning all the technologies within the first 4 weeks, participants are expected to develop the below given casestudy... scripting language, PHP. Integrate all the above tasks and make the XYZ.com
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++ - Development process
c/c++  Ive been asked to develop a backgammon game using C language. I don't know which code to use to move checkers and to roll die. I would appreciate to get some help. Thanks
c/c++ - Development process
c/c++  Ive been asked to develop a backgammon game using C language. I don't know which code to use to move checkers and to roll die. I would appreciate to get some help. Thanks
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 <
Change font in swing?
Change font in swing?  I want to use marathi language on labels,buttons
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
C++ programing
C++ programing  how to change constants to be randomly generated
For C++ programmers
always start with an upper case character, Methods (called functions in C..., but the name change is intended to show that you can't use them as C++ pointers... Java NotesFor C++ programmers Java inherited many features from C
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

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.