I have input like the following:
Someting sth
example
5 15
3
I want to scanf
input by lines to get whole content of the line. But when reaching first digit (there can be spaces/tabs before it) I want to scanf it as int.
That's what I have come up with but it does not work as expected - cursor still does not stop at digit character.
char person_name[1000];
int n;
while (scanf("%[^\n/D]%*c", person_name) > 0) {
if (checkIfContainsNumber(person_name) == 0) {
appendToLinkedList(&head_ref, person_name);
} else {
break;
}
}
while (scanf("%d", &n) > 0) {
printf("%d ", n);
}
scanf("%s", person_name);
thenif(isdigit(person_name[0])) { int num = atoi(person_name); }
– Weather Vanescanf("%s", person_name);
then I read words by words and not by line. I need to distinguish if there are more words in the same line. – Epsilon47" %[^\n]"
to filter the leading whitespace. – Weather Vanescanf(" %[^\n^0-9]%*c", person_name)
- the space in front of%
helped. Thanks a lot. – Epsilon47