c - When using strtol and input 2 zeros (00), then it only output one zero back? -



c - When using strtol and input 2 zeros (00), then it only output one zero back? -

the code below asks age , outputs simple printf. im trying input 000 , have homecoming 000 , not 0. do?

#include <stdio.h> #include <stdlib.h> #include <string.h> #define line_len 80 #define extra_spaces 2 int main(void) { char line[line_len + extra_spaces]; char * end; int input_num; /* user input */ printf("please come in age: "); fgets(line, line_len+extra_spaces, stdin); /* check buffer overflow */ if(line[strlen(line)-1]!='\n') { printf("error: buffer overflow\n\n"); homecoming exit_failure; } /* remove newline */ line[strlen(line)-1]=0; /* retrieve number */ input_num = strtol(line, &end, 0); if(*end) { printf("error: info entered not numeric.\n\n"); homecoming exit_failure; } printf("you %d years old.\n\n", input_num); homecoming exit_success;

}

if understood question correctly, need this:

printf("you %03d years old.\n\n", input_num);

c

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -