dimanche 8 novembre 2020

The goal is to read two strings into 2 different variables. Then we count the number of "C" in each string and output the result

Here is what I did:


int main ()
{
  int count = 0;
  int i, j;
  char firstLine[10000000];
  char secondLine[10000000];
  scanf("%s", firstLine);
  scanf("%s", secondLine);
  
  for (i=0;i<10000000;i++) {
      if (firstLine[i] == 'C') {count++;}
  }
  for (j=0;j<10000000;j++) {
      if (secondLine[j] == 'C') {count++;}
  }
  printf("%d", count);
  
  
  return 0;
}

I think it makes sense but there is some sort of segmentation error according to my compiler. What am I missing?

For example, an input of AB BBAAB should yield an output of 0.

Aucun commentaire:

Enregistrer un commentaire