Funkcja nie pozwala mi wpisać czegokolwiek z klawiatury

0

W addc() po pierwszym printf program nie reaguje na to, co chce mu wpisać z klawiatury. Proszę o pomoc.

 #include "fun.h"

const int max_n= 10;



int addc() {
     char tmp1[max_n+1], tmp2[max_n+1], tmp3[max_n+1], tmp4[max_n+1], *tmpx;
     int i=0,k=0;
     
     do {
     printf("Type ID of a car: ");
     /*scanf("%s", &tmp2);*/
     fgets (tmp2, max_n, stdin);
     
     for (i=0; i=NRECORDS; i++) {
         k=(strcmp(tmp2,cars[i].carid));
         if(k=0)
         printf("ID incorrect\n");
     }
     
     } while (k=0);
     
     cars[i].carid = fgets (tmp2, max_n, stdin);
     
     printf("Type mark of the car: ");
     fgets (tmp3, max_n, stdin);
     cars[i].mark = tmp3;
     
     printf("Type model of the car: ");
     cars[i].model = fgets (tmp4, max_n, stdin);
     
     }
int add()
{
     char b;
     
     printf("Please choose which type of record yoou want to add:\n\n");
     printf(" c - car record\n s - service record\n\n Your choose: ");
     
     while((b=getchar()) !=  EOF ) {
                         switch(b) {
                                   case 'c': addc();
                                   case 's': adds;
                                   default: printf(" ");
                                   }
                         }    
}
0

A newline character makes fgets stop reading, but it is considered a valid character and therefore it is included in the string copied to str.

Wciśnij drugi raz enter. Tak mi się przynajmniej zdaje.

0

Jak wykluczam (komentarzem) całego pierwszego printf aż do kolejnego, to następne printf i fgets działają. Może coś w do while jest nie tak

0

ok ma być tak:

 
#include "fun.h"
 
const int max_n = 10;
 
 
 
int addc() {
     char tmp1[max_n+1], tmp2[max_n+1], tmp3[max_n+1], tmp4[max_n+1], *tmpx;
     int i=0,k=0;
 
     do {
     printf("Type ID of a car: ");
     /*scanf("%s", &tmp2);*/
     fgets (tmp2, max_n, stdin);
 
     for (i=0; i==NRECORDS; i++) {
         k=(strcmp(tmp2,cars[i].carid));
         if(k==0)
         printf("ID incorrect\n");
     }
 
     } while (k==0);
 
     cars[i].carid = fgets (tmp2, max_n, stdin);
 
     printf("Type mark of the car: ");
     fgets (tmp3, max_n, stdin);
     cars[i].mark = tmp3;
 
     printf("Type model of the car: ");
     cars[i].model = fgets (tmp4, max_n, stdin);
 
     }
int add()
{
     char b;
 
     printf("Please choose which type of record yoou want to add:\n\n");
     printf(" c - car record\n s - service record\n\n Your choose: ");
 
     while((b=getchar()) !=  EOF ) {
                         switch(b) {
                                   case 'c': addc();
                                   case 's': adds;
                                   default: printf(" ");
                                   }
                         }    
}
 

1 użytkowników online, w tym zalogowanych: 0, gości: 1