Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
This is input: Francetic, Petra#13/12/1930 Trg zrtava Uskoka 156 (Skopje) 800893452/2008
It wont fscanf properly it show's m=0 and that's how I know that while loop was not successful.
while(fscanf(mrtvaciTxt, "%[^,],%[^#]#%d/%d/%d %[^0-9]%d (%[^)]) %[^/]/%[^\n] ",
&pomrli[m].prezime, &pomrli[m].ime,
&pomrli[m].dan,&pomrli[m].mjesec,&pomrli[m].godina, &pomrli[m].adresa,&pomrli[m].brUlice,
&pomrli[m].brOsobne, &pomrli[m].godSmrti )== 9)
{
m++;
}
printf("%d\n\n", m);
How can I fscanf this and is there any tutorial how can i be better at this because it takes me so much time.
Francetic
Petra
13
12
1930
Trg zrtava Uskoka 156 (Skopje)
800893452
2008, I want fscanf to look like this
There are multiple errors in the scanf format.
Here is the correct scanf format string:
" %[^,], %[^#]#%d/%d/%d %[^(](%[^)]) %[^/]/%d"
Here is the list of errors:
there are 11 % while you expect only 9 fields
lacking a space in front of the format string to consume the newline
there is a / in front of the first %d which shouldn’t be there
you are using a [^\n] where you should use [^(]( for the adresa
you are using %*[\n] for unknown reason
you should use [^)] to get the grad
etc.
you modified you question, so I don’t know what else you did.
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 11 months ago.
Improve this question
I'm a beginner and I'm creating a C program to print numbers from 0 to n using while loop where n is input from user.
//program to print numbers 0 to n where n is input from user
#include<stdio.h>
int main()
{
int i=0,num;
printf("Enter number: ");
scanf("%d",&num);
while(i<=num)
{
printf('%d',i);
i++;
}
return 0;
}
Im getting error saying expected const char
I tried to get solution over several websites
since im new to this language I'm facing trouble in such simple code
I tried running this code on several online compilers but everywhere I get the same issue
In line 11 in the printf statement you have used single quotes - '%d' which does is giving you problems here, change it to a "%d". Hope that helps.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I got some warning in my code. Is there someone who can help me?
I tried to change %d to %f but the program will then not work as I want to, like with the warnings.
In the line
printf("%d |%.2f \n", MOVE_FORWARD * i, i, MOVE_FORWARD);
You are doing three things wrong:
i) You used more arguments than format specifiers, you have 2 format specifiers and used 3 arguments namely (MOVE_FORWARD *i), (i) and MOVE_FORWARD
, you used printf to print only 2.
ii) You used wrong specifiers, MOVE_FORWARD * i is of type double, not integer.
iii) i is of type integer not double.
The correct way should be:
printf("%f |%d \n", MOVE_FORWARD * i, i);
if you want to print those two.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I have an ASCII string coming from UART that looks something like "43.533a,5532" and I'd like to extract the two numbers. My idea was to separate them using strtok with the comma as delimiter and then remove the last character from the first string and afterwards convert the numbers using atoi() or is there an easier way with sscanf()? String manipulation is nothing I'm regularly using.
Another problem is, if the String looks different, how could I catch that beforehand?
Yes you can do this easily with sscanf().
Following is an example. See it working here:
#include <stdio.h>
int main(void) {
float a;
int b;
char *sNum = "43.533a,5532";
sscanf(sNum, "%fa,%d", &a, &b);
printf("a= %f || b= %d", a,b);
return 0;
}
Output:
a= 43.533001 || b= 5532
Note: Since float is having precision to 6 decimal place by default, so you may need to consider it and correct it if necessary.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
For example it prints '(night' despite tokenizing (), why does this happen?
char* word = strtok(&c, ",.;()");
while(word!= NULL)
{
word = strtok(NULL, ",.;()");
printf("%s ", &c);
}
Your code just prints &c on every iteration (whatever that is). You never print word, which is your next token. That's why you never see the results of your tokenization. If you want to see the tokens, you have to print word, not c.
On top of that it is completely unclear why you are applying & operator to your c. If c is a string pointer or a char array, that & there makes no sense at all.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
My C code is :
void main()
{
int a=5,b=6,c=11;
clrscr();
printf("%d %d %d");
getch();
}
When i compiled it , it is giving Compile time error but the answer to this question is : 11 6 5
I'm unable to understand how the output is 11 6 5
Please somebody tell the correct output with proper explanation .
Thanks
its behavior is undefined. if you want to show the values of a, b and c you should have coded as below:
printf("%d%d%d",a,b,c);
now the output is:
5 6 11
The program has undefined behaviour, since the printf format string requires that you pass three additional int arguments, which you aren't doing. Anything could happen. Printing certain output is one form of "anything".
Program's behavior is undefined. You well get anything.
You are passing no arguments to the printf function while it is expecting three int type arguments. The statement
printf("%d %d %d",c, b, a);
will give you desired output.
11 6 5