Hello guys. I have a matrix with char.

#define MAX_CHAR 128
#define MAX_SIRURI 10
char siruri[MAX_SIRURI][MAX_CHAR];

I must read the number of strings ( n ), and after that, to go through each string. I must read each string, after that, to show it, and to find for each one, the number of characters, the number of sentences and how many 'a' & 'A' got the sentence.

Here is the whole program

#include <stdio.h>
#include <conio.h>
#define MAX_CHAR 128
#define MAX_SIRURI 10

void main(void)
	int n, k, i, j,
		nrcuv[MAX_SIRURI] = {0},
		nrAa[MAX_SIRURI] = {0},
		nrchar[MAX_SIRURI] = {0};

	char siruri[MAX_SIRURI][MAX_CHAR];

		printf("How many strings do you want ?\n");
		scanf("%d", &n);
	while(n > MAX_SIRURI || !n);

	for(i = 1; i <= n; i++)
		printf("Give string %d: \n", i);

		nrcuv[i] = 1;
		gets(siruri[i]); // read string[i]
		printf("\The string is: %s\n\n", siruri[i]);

		for(j = 0; siruri[i][j]; j++) nrchar[i]++; // the number of characters
		for(j = 0; siruri[i][j]; j++) // the numbers of 'a' & 'A', the sentences
			if(siruri[i][j] == 'a' || siruri[i][j] == 'A') nrAa[i]++;
			else if(siruri[i][j] == ' ') nrcuv[i]++;

And here is the problem ... :
- i read the number of strings ( n )
- and when the program enters in for, it skips the first string ...
- here is the result: (after i read n ) http://img852.imageshack.us/img852/144/errorm.png

When the call to scanf in line 18 returns, it leaves unread in the input stream the first character that cannot possibly be part of an integer. In this case, that is the newline that ends the input.

As a result, the first call to gets reads an empty line, namely the one that is terminated by the newline that was left in the input.

Two additional comments:

1) You should never use gets, because there is no way to specify a limit on how much memory it will overwrite. As a result, any program that uses it has potential security problems that are impossible to fix.

2) This is a C program. Why are you posting it in a C++ forum?

This article has been dead for over six months. Start a new discussion instead.