0

This is a problem of URI online judge.Problem no.1914 beginner.According to my code if i give input 4 then the the program should read strings 4 times and also integer 4 times each time two integer.but the program are only taking 4 times input either 4 times string or 4 times integer or 2 times string+ 2 times integer.

#include <stdio.h>
int main()

{
    char name[1000][100],ch;
    int a,b,c,i,j=0,k,n[1000][2];
    scanf("%d",&a);
    for(i=0;i<a;i++)
    {
        gets(name[i]);
        for(k=0;k<2;k++)
        {
            scanf("%d",&n[i][k]);
        }
    }
}

if inputs are

4
Quico PAR Chiquinha IMPAR
9 7
Dami PAR Marcus IMPAR
12 3
Dayran PAR Conrado IMPAR
3 1000000000
Popis PAR Chaves IMPAR
2 7

After taking 4 lines of input the program end.If u can help help with that please help.

quico PAR chiquinha IMPER
9 7
dami PAR marcus IMPER
12 3
  • It's not the source of your problem, but never, ever, use `gets()`. Use `fgets()` instead. – John Bollinger Jun 21 '19 at 20:53
  • You will need to actually use Scanf to get the input from the Characters Line and break it up into four pieces, which will automatically work based off the spaces in the line. likewise, you will need to grab both numbers picked in one go on the next line Likewise you won't need an inner loop. Your other option is to accept the whole line each time and then split it into pieces and assign it to variables afterward, however, `scanf` will do the needful in splitting up the variables while reading them. – Ben Personick Jun 21 '19 at 21:12

1 Answers1

0

Read this- https://www.geeksforgeeks.org/problem-with-scanf-when-there-is-fgetsgetsscanf-after-it/

Your scanf is leaving a newline on the buffer.

pcopp
  • 21
  • 4
  • 1
    This identifies the problem correctly, and it barely avoids being a link-only answer, but ... it barely avoids being a link-only answer. – John Bollinger Jun 21 '19 at 20:59