All Questions
6,621
questions
0
votes
3
answers
83
views
Trying to read txt file line by line in C Language
Basically my input file is in the format:
I 15 3 15 10 10 20
S -5 3 15 82
I -20 80 -4 10
S 4 -20 8
The number of ints in a row can vary, but there is always one char at the beginning of each ...
3
votes
3
answers
109
views
Why doesn't scanf("%d %d") complain about decimal input?
Why when I run this code:
#include <stdio.h>
int main () {
int a, b;
if (scanf("%d %d", &a, &b) == 2)
printf("%d %d", a, b);
else
printf(...
1
vote
2
answers
114
views
simple calculator program exiting unexpectedly after input (C, MinGW)
'm trying to write a basic calculator program in C using MinGW. However, the program exits unexpectedly after I enter the operator (+, -, *, or /). I've checked for common errors like missing return 0;...
1
vote
4
answers
116
views
Shouldn't this be considered a double pointer?
I'm a novice C programmer, and I have what is probably a simple question. I'm learning about using pointers to structs currently, and I can't understand why lines 20 or 22 below work. I understand ...
0
votes
2
answers
60
views
Code output repeats the else section of this if else section
Soo, whenever I run this code, it only repeats the last section on the if else block. It only outputs that one printf repeatedly.
I did use the sscanf thing to check if I can and to prevent buffer ...
0
votes
1
answer
60
views
How to fix warning - Unbound scanf conversion
I am trying to use the following in my code :
int val;
val = sscanf ( line_pointer, "%u,%u %s %s", &unit_id, &subprogram_id, flags.get(), slotDescriptionPtr.get() );
But getting ...
-1
votes
1
answer
80
views
Saving a character to an int variable using scanf( ) making unexpected char equivalent int value
I was checking library function isupper() to check if the function version or macro version of
isupper() is efficient depending on storage used or runtime and I have this peculiar problem
when using ...
4
votes
2
answers
68
views
Is there any easy way to map windows specific secure C-API funcs to functions that will work on mac? (ex: sscanf_s)
I am currently trying to compile a library for MacOS that was originally written for Windows. This library's source makes use of lots of Windows secure functions like sscanf_s()
Obviously, clang is ...
0
votes
4
answers
86
views
Avoiding buffer overflow at scanf using a macro determining string length [closed]
I've got an assignment where I have to acquire a string input whose length must not be greater than, say, 32. This length is given by a macro called MAX_BUF_LEN. I found solutions on StackOverflow ...
0
votes
1
answer
66
views
How can i use fscanf from file to struct in c?
I cannot save information of students from file to struct. When I tried to printf my struct its not working.
I think it should work but I dont understand why it is not working. When I did only struct ...
1
vote
2
answers
83
views
sscanf gave me unexpected result
I am learning C language. This is my code run in linux.
#include <stdio.h>
int main(int argc, char *argv[]){
char string[] = "Rudolph is 12 years old";
char str[20] = {0}
...
1
vote
1
answer
80
views
Typedef instances only saves the last input
I'm trying to get a few(3 for now) names as the candidates for a vote and assign them to typedef instances with the array I have defined. But when I run the code only the last name gets saved in the ...
1
vote
1
answer
64
views
Why does scanf take two inputs when running this code? [duplicate]
When using the scanf function to take an input, two inputs are given.
For starters, I am a python programmer trying to learn C. I tried to search why this was happening but found nothing. Here is the ...
-1
votes
1
answer
50
views
Different Output for Same Input in C Program: Struct Array Initialization [closed]
I'm encountering a perplexing issue with a C program involving struct array initialization. Despite providing the same input values for both the x and y members of a struct point array, I'm observing ...
1
vote
2
answers
99
views
sscanf: how to parse
I'm trying to parse this string:
+CGDCONT: 0,"IP","free","10.158.88.34"
In bold are the items i'm interested in.
My first attempt was to use this pattern:
"+CGDCONT: ...