## ilkeamasya

As you see at below I used "-1" as my sentinel value but my program wants the other 6 values i asked for in scanf too. How can i solve this problem? I just want the user to enter -1 and exit my loop. I would greatly appreciate for your help..
Regards..

``````#include <stdio.h>
#include <math.h>
#include <ctype.h>

#define N 100
#define ISIMUZUN 15

struct student{
char name[ISIMUZUN];
char surname[ISIMUZUN];
int number;
float final;
float midterm;
float hw1;
float hw2;
char *letter;
};
int main(int argc, char *argv[])
{

struct student info[N];
int i=0, total=0,total2=0,j=0;
double mean=0, stddvt=0, temp=0;
int studentcounter=0,aacount=0,bacount=0,bbcount=0,cbcount=0,cccount=0,dccount=0,ddcount=0,ffcount=0,vfcount=0;
float midtotal=0,midavr=0,fintotal=0,finavr=0,hw1total=0,hw1avr=0,hw2total=0,hw2avr=0;

do{    printf("Please enter student's information with blanks between them\n");

scanf( "%d %s %s %f %f %f %f", &info[i].number, info[i].name, info[i].surname, &info[i].midterm, &info[i].final, &info[i].hw1, &info[i].hw2   );
info[i].grade = (info[i].final*0.4)+ (info[i].midterm*0.25)+ (info[i].hw1*0.15) + (info[i].hw2*0.20);
if(info[i].number==-1)
break;
studentcounter=studentcounter+1;
i++;
}while  (info[i].number!=-1);``````

## gerard4143 371

Don't request everything in one scanf call. Call scanf for your sentinel value the check the result and then call scanf for the remainder.

## ilkeamasya

Don't request everything in one scanf call. Call scanf for your sentinel value the check the result and then call scanf for the remainder.

But i needed to have all information with blank space. Is there another way to do it as i wanted?

By the way, I can not print letter

``````char *letter;
info[i].letter= "AA";``````

with

``printf("%s\n",info[i].letter);``

code. I thought using as a pointer would be better as you have said but can not print it out. Any idea about that?

## Banfa 597

Calling scanf twice does not mean the user has to enter the data on more than one like. There is no implied reading of a new line character at the end of a scanf call.

scanf just requires whitespace between fields which is space, tab, newline, carriage return but it is not at all fussy about which ones it gets.

## ilkeamasya

Thank you very much.. I think now my sentinel value works perfect. Do you have any idea about printing the pointer ?

## abhimanipal 91

``````char *letter;
info[i].letter= "AA";``````

This code is wrong. When you say char* letter you just have a pointer. For storing data the pointer has to point to some memory. Check out the function malloc

## ilkeamasya

I see. Thanks for your replies. Everything is working in my code as it should. One quick question if i may :

``````printf("Student Number             Student Name           Grade   Letter\n");
printf("================  ==============================  =====   ======\n");

for(i=0;i<studentcounter;i++){