Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- void trimCR(char *t) {
- if (t[strlen(t)]=='\0') {t[strlen(t)-1]='\0';} //set last byte-1 to null
- }
- void main() {
- char tmp[64];
- int num;
- printf("Enter something: ");
- if (fgets(tmp,sizeof tmp,stdin)) {
- num=atoi(tmp); //extract a number from our text
- trimCR(tmp);
- printf("I found the number %d inside '%s' which is %ld characters!\n",num,tmp,strlen(tmp));
- } else {
- printf("There seems to be an error with your input\n");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement