-6

I have created a program on Pelles C, however, when I run it, it is skipping straight to the end of the function simply saying "press any key to continue"

#include <stdio.h>

int main()
{
    char letter;
    int num1, num2;

    printf("Enter any one keyboard character ");
    scanf("%c", &letter);
    printf("Enter 2 integers seperated by a space ");
    scanf("%d %d", &num1, &num2);

    printf("Numbers inputted were %d and %d \n" num1, num2);
    printf("letter input %c", letter);
    printf(" Stored at: %p \n", &letter);

    return 0;
}

Can anybody tell me why this is happening ?

cbr
  • 12,563
  • 3
  • 38
  • 63
  • 1
    Please read the guidelines to asking a question on Stack Overflow. [http://stackoverflow.com/help/how-to-ask] "Can somebody help me?" is not a valid title (or question). The title should explain something about the problem you are seeking help for. – Dale Wilson Jul 13 '15 at 17:02
  • 1
    don't use `scanf()` for getting user input, especially not when you are reading individual characters. Use `fgets()`, `fgetc()`, etc. – The Paramagnetic Croissant Jul 13 '15 at 17:02
  • 2
    Are you sure **this is actually** the code that you are having trouble with? Beside the missing comma (which may be a typo or a proof that you didn't even compile it), this program works when compiled with my VS2013 and with my gcc. –  Jul 13 '15 at 17:06
  • 2
    Are you sure you're even compiling it and not running the last working version? – cbr Jul 13 '15 at 17:09
  • Step through it with the debugger. – Jabberwocky Jul 13 '15 at 21:33

1 Answers1

1
printf("Numbers inputted were %d and %d \n" num1, num2);
                                           ^

You missed a , before num1 in above printf statement.

printf("Numbers inputted were %d and %d \n",num1, num2);
ameyCU
  • 16,489
  • 2
  • 26
  • 41
  • I have edited that statement, however when running the program it still goes straight to the end saying "Press any key to continue" I would screen shot the program but I do not have the necessary reputation to post images. – Aztec warrior Jul 13 '15 at 17:03
  • 1
    @FlewittConnor Ar you sure this is the same code that creates problem and you have not edited original to post here. Maybe you removed the portion that may create problem other than the mistake ? – ameyCU Jul 13 '15 at 17:10
  • I Have copied the code, closed the program, opened a blank program, and pasted the code. and it now works fine, haven't a clue how as the code was exactly the same but it is now working. – Aztec warrior Jul 13 '15 at 17:17
  • 1
    @FlewittConnor You must have not compiled it before running that's why. – ameyCU Jul 13 '15 at 17:24