C :(

Discussion on Coding.
Post Reply
pelmeen
Regular
Posts: 50
Joined: Thu May 19, 2005 4:19 pm

Post by pelmeen »

it asks that to write a number...i enter but i closes right after this...i dont c it saying You entered %d
in c++ i could use cin.get();
but not in C :P

Code: Select all

#include <stdio.h>

int main()
{
  int this_is_a_number;

  printf( "Please enter a number: " );
  scanf( "%d", &this_is_a_number );
  printf( "You entered %d", this_is_a_number );
  getchar();
}


and this says that it is wrong :(
it is in C it says smthing is wrong in printf line :S

Code: Select all

 #include <stdio.h>

int main()
{
  printf( "I am alive!  Beware.\n" );
  getchar();
  return 0;
}
Jaap
Loyal fan
Posts: 390
Joined: Thu Apr 22, 2004 8:21 am

Post by Jaap »

Code: Select all

#include <stdio.h>

int main(void) {
  char buffer[81];
  int i, ch;

  /* Read in single line from "stdin": */
  for(i = 0; (i < 80) && ((ch = getchar()) != EOF) && (ch != '\n'); ++i) {
    buffer[i] = (char)ch;
  }

  /* Terminate string with null character: */
  buffer[i] = '\0';
  printf("Input was: %s\n", buffer);
}
Post Reply