none
Programming in C syntax error C2143

    Question

  • hi, I wrote  this program and for some reason i keep getting the error : error C2143: syntax error : missing ';' before 'type'

    this is the program 

    #include<stdio.h>

    #include<string.h>

     

     

    int main(void)

    {

    int i =0;

    int count =0;

    char c;

    char sentence[100];

    char letter;

     

    printf("what letter do you want to count: ");

    scanf("%i \n", &letter);

     

    puts("enter a line of text: ");

     

    while (( c= getchar()) != '\n')

    {

    if (c == letter)

    {

    ++count;

    }

     

    sentence [ i++ ] = c;

     

    }

     

    sentence [i] = '\0';

     

    puts("\n the line entered was: " );

    puts("sentence");

     

    printf("the number of %d's are : ", letter);

    printf("%d", count);

     

    return 0;

    }

    i dont know what else to try. please help 

    Saturday, May 07, 2011 5:52 AM

Answers

  • Hi eleyeth

    In stead of scanf("%i\n",&letter); you should have

       scanf("%c",&letter);

         fflush(stdin);

    Also puts("sentence") should be puts(sentence).

     Also printf("the number of %d are:",letter); should be printf("the number of %c are",letter);

    Best regards

    Chong


    • Marked as answer by eleyeth Saturday, May 07, 2011 3:01 PM
    Saturday, May 07, 2011 7:08 AM

All replies

  • Hi eleyeth

    In stead of scanf("%i\n",&letter); you should have

       scanf("%c",&letter);

         fflush(stdin);

    Also puts("sentence") should be puts(sentence).

     Also printf("the number of %d are:",letter); should be printf("the number of %c are",letter);

    Best regards

    Chong


    • Marked as answer by eleyeth Saturday, May 07, 2011 3:01 PM
    Saturday, May 07, 2011 7:08 AM
  • eleyeth wrote:

    hi, I wrote this program and for some reason i keep getting the error  : error C2143: syntax error : missing ';' before 'type'

    I don't get this error when I compile your code. This means the code  you've posted is not the same code you are actually compiling.

    Post the exact complete error message, as well as the line of code it's  referring to.


    Igor Tandetnik

    Saturday, May 07, 2011 1:24 PM
  • that was the program, maybe your compilers better than mine or something 
    Saturday, May 07, 2011 3:02 PM
  • thanks did all that and it works now 
    Saturday, May 07, 2011 3:02 PM
  • eleyeth wrote:

    that was the program, maybe your compilers better than mine or  something

    So, what line of code does your compiler say is in error? Once again,  post the exact complete error message, as well as the line of code it's  referring to.


    Igor Tandetnik

    Saturday, May 07, 2011 3:56 PM