Thread: problem with gets

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    1

    Question problem with gets

    hi
    i wroth this program :
    as soon as i change gets to scanf in /*/line it works properly otherwise it does not work!!
    i woner why??
    the problem is with the second gets as if it does not works
    i have to use gets because i need to read in a string instead of a word!
    #include<stdio.h>
    #include<stdlib.h>
    #include<string.h>
    typedef struct{
    char name[30];
    float mark;
    }person;

    main(){

    person m1;
    person n1;
    int flag=0,counter=0;

    puts("enter the first name");
    gets(m1.name);
    puts("enter the correspondence mark");
    flag=scanf("%f",&m1.mark);

    while (flag!=EOF){
    counter++;
    printf("enter the next name\n");
    /*/ gets(n1.name);
    printf("enter the correspondence mark\n");
    flag=scanf("%f",&n1.mark);
    if(n1.mark>m1.mark)
    m1=n1;
    }
    if(counter)
    printf("the best student is %s and his mark is %.2f",m1.name,m1.mark);
    else
    puts("you did not enter any record");
    }
    Last edited by bsimaie; 04-16-2003 at 09:13 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 04:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM