All Questions

Tagged with
Filter by
Sorted by
Tagged with
0
votes
0answers
11 views

Incorrect Matrix scanned from txt file in c

I scan a matrix from a txt file, and print out the scanned value. As shown in the first for loop, the matrix printed is correct. However, the matrix printed in the second for loop is incorrect in the ...
0
votes
0answers
37 views

sscanf in c couldn't parse string

Please have a look into the following code. #include <stdio.h> void main(){ char driver_list[128] = {"123456,fariz,12345678,012-345-6789\n" "234567,ɽﻨ,23456789,...
0
votes
1answer
25 views

Trying to create a 2d array by inserting characters retrieved from file stream

This is my code: #include<stdio.h> #define ROW 10 #define COLUMN 20 int main(int argc, char *argv[]){ FILE* fptr; char grid[ROW][COLUMN]; int i ,j; fptr = fopen(argv[1],"r"); for ( i =...
-1
votes
0answers
33 views

scanf long long int int c codeblocks [on hold]

I'm using code blocks with c99. I tired getting a long long int input using: long long int num; scanf("%lld", &num); No matter what I tired it is not working. ps. long int and scanf("%ld", &...
1
vote
2answers
34 views

Putting text in scanf makes the code output random numbers?

I am learning C in my computing class and we were introduced to scanf today. This is the line of code that was used to introduce scanf: #include <stdio.h> void main() { float x,y; scanf("%f %f"...
1
vote
2answers
31 views

About Ovewriting variables in scanf()

I am creating a test program that shows an error message when an entered number is less than, or equal to, ten: #include <stdio.h> void errorMessage() { printf("\n This number is less than, ...
-1
votes
2answers
47 views

passing char array to function from scanf in c

I have following function in c code void analyze_text(char text[]) { ... for (int i = 0; i < text_length || text[i] != '\0'; i++) { ... } } In main function i would like to pass ...
1
vote
1answer
35 views

How do I scan less chars than defined into an array?

I've encountered a problem while trying to scan chars into an array. This is the scan loop - char letter[6] = {0}; for(int i = 0; i <= 5; i++) { scanf(" %c", &letter[i]); } The desired ...
0
votes
2answers
23 views

(C/C++) fscanf_s Missing Integer Arguments error When Reading in Chars to Array from txt file

First Post, will do my best to follow guidelines and make this a proper setup. If ANYTHING is needed, let me know! The error in VS 2019 is "C6064: Missing integer argument to 'fscanf' that ...
1
vote
1answer
42 views

forcing the buffer to clear in scanf

i have a problem with scanf and input buffer in my program. first i ask the user for input : char someVariable; printf("Enter text: "); scanf(" %c",&someVariable); and then i have a loop that ...
0
votes
1answer
51 views

why is scanf causing infinite loop when entering a char different than number? [duplicate]

int main() { int choose, isNum; printf("Choose 1,2,3,4,5,6\n"); isNum = scanf("%d",&choose); while(choose != 0){ if(!isNum || choose > 6){ printf("Wrong ...
2
votes
1answer
61 views

“scanf” as a condition in while loops

I need to determine the size of an input (potentially infinite) using the "scanf" function. Now I have limitations so I cant use strings, arrays, or basically anything that is not the function. char ...
0
votes
1answer
28 views

How Do I Store Contents of a File into an Array (C)

FILE *pFile; pFile = fopen("address01", "r"); int yup[8]; int* array[7]; for (int i = 0;i < 7; i++) { while (!feof(pFile)) { fgets(yup, 8, pFile); puts(yup); //It DOES ...
0
votes
0answers
29 views

How to check if the scanned double is actually a double integer [duplicate]

#include <stdio.h> #include <stdlib.h> int main(void) { double x; scanf("%lf", &x); if(x != (long)x) { printf("invalid input"); } else{ printf("valid"); } } ...
0
votes
1answer
35 views

scanf doesn't take the input until I hit enter twice

scanf is not skipped. It waits for me to enter input, but I have to enter the value and hit enter twice (the second input is properly saved). int yes(void) { int yes, rc, isValid; char ...
0
votes
1answer
39 views

How to read file with delimiters using fscanf?

I am trying to read a file and store the information to the following buffers char bookCode[MAX]; char title [MAX]; char author [MAX]; char year [MAX]; float selfCost; float ...
-1
votes
1answer
59 views

fscanf is duplicating numbers while reading from a file

I am trying to read numbers from a file and put them into a 2d array, but the first number of each line is being put into the place of the last number of the previous line. output should look like ...
0
votes
2answers
43 views

while loops , int vs char reading from scanf , true and false

#include <stdio.h> int main() { int number; // We make 1 int named number scanf("%d",&number); // We give to number some number xd while (number!=0)// We made a loop while if ...
0
votes
1answer
27 views

return value of scanf() for string

This code ... void main() { char str[5]; long int c=scanf("%s",str); printf("\n%p %p %p %p", c, &str[0], &str[1], &str[4]); } ... gave output: ... bhjun //thats the input 0x1 ...
-1
votes
0answers
30 views

Why I'm getting Bus error when running on 32-bit machine while it works fine on 64-bits

Wrote a c code that will read data from the excel sheet using sscanf. When running the same code on 32-bit machine, it gives me bus error. The same code works on 64-bits machine. Here the gdp debug ...
0
votes
1answer
39 views

How to stop fscanf() from duplicating values?

char hexe; int hex1; FILE *pFile; pFile = fopen("address01", "r"); while (fscanf(pFile,"%c %d",&hexe, &hex1) != EOF) { //ERROR likely here printf("%c %d", hexe, hex1); ...
-4
votes
0answers
30 views

sscanf gives segfault from within [duplicate]

I am reading a file line by line, and when the first character of a line is "o", I want to start reading the rest of the line and print it out. Note: the first "o" is always followed by a space, so I ...
-4
votes
1answer
93 views

Usage of *variable in scanf and why we use it? [closed]

hello i'm a beginner and i keep seeing this in codes but i cant figure what exactly it means... like the example below #include<stdio.h> int main(void) { char c1; do { ...
0
votes
1answer
21 views

Scanf ignore some types of inputs

in my program i use the scanf function like this: if(((scanf("%c %d %d",&zp, &min, &max)) != 3) || (zp != 'c' && zp != 'l') || min < 0 || min > max){ ...
-1
votes
0answers
25 views

Why fscanf jumps directly to EOF? [closed]

I have an array of structs and reading data from file in this format: NAME HEIGHT WEIGHT NAME HEIGHT WEIGHT ... But every time it goes to the EOF and does not even read in the data. Any ideas? #...
0
votes
1answer
28 views

How can I initialize a 2d Array with no rows or columns, and create a function that takes user input, then updates the 2d array?

My real goal here is to initialize a 2d array, then call a function to get user input for the rows and columns, and then return the 2d array to main with the size that the user specifies. Though I ...
1
vote
3answers
52 views

Why scanf doesn't work with spaces at the end of formal input?

I'm trying this: int M,N,K; printf("Enter (m,k,n) : "); scanf("%d %d %d ", &M, &K, &N); printf("\nDone?"); This is inside the main function. I need the program to read ...
1
vote
1answer
37 views

unknown error the function 'scanf(“%[^\n]%*c”, &sent);'

Getting to point, I am a beginner in the C language and just encountered a weird method of inputting string in a C Program: #include <stdio.h> #include <string.h> #include <math.h> #...
0
votes
1answer
29 views

C - scanf to pull a number in quotes only after a specific sequence of characters

Say I have a string like this: Hello World - this is a line of textCOLOR="4" and this string is stored in buf[1000] As you can see this string has a color tag in the format of COLOR="n". The ...
0
votes
0answers
14 views

How do I display a textfile that contains Extended ASCII characters and store it into an array afterwards?

I am currently designing level maps for my game project in which I designed it by using Extended ASCII characters in a textfile. However, I am unsure on how to display them and store each character ...
-3
votes
1answer
56 views

force scanf(“”) to only receive a number 0-7

I have a task to write a code that would receive a number from 0 to 7 (including edges) and convert it to 4bit binary code in two's complement. everything is fine with my code. it works and ...
-1
votes
1answer
46 views

Last letter is input + 1 for some reason

I'm doing an exercise to print 3 letters taken from the user. The first two letters end up fine, but the last one is always the letter that comes after what the user inputs for some reason (I've tried ...
0
votes
1answer
50 views

How to check when you scanf that you get only integer (like 2) and not integer followed by char (like 2c)

I'm trying to scanf an integer to see if it's legal in my program. However, if I input a number followed by a char it still treats it as legal number (my guess is that it only refers to the integer ...
0
votes
0answers
32 views

Using sscanf to read multiple fields delimited by tab - C

I've been struggling with that like 3 days, trying to implement the right way to do that. I've used the way of: %[^\t]... But it seems not to cover all the cases. We are required to receive a line ...
1
vote
2answers
36 views

Why is the first value of my char array 10?

I'm new to programming but I wanted to make a program that gets as input a number, (length) and then stores a series of a's and b's of said length. Finally it should output the numbers as the ascii ...
1
vote
1answer
42 views

Why the value of a integer variable is changing after reading a string with scanf?

Ley us consider the following piece of code: #include <stdio.h> #include <stdlib.h> #include <ctype.h> #include <string.h> int main(){ char again = 'Y'; int code; ...
-2
votes
1answer
49 views

Scanf stores wrong value inside integer variable

I have wrote the following code using c programming language (Standard 89): #include <stdio.h> #include <stdlib.h> int main() { int cc,dd; scanf("%d/%d",&cc,&dd); ...
0
votes
1answer
39 views

How can sscanf read until whitespace or tab or newline

I've got some assignment on programming course I'm taking this term on C and got some trouble with using sscanf function. The program is actually supposed to receive from the user a line of student's ...
-2
votes
2answers
41 views

My Program do not take input from the scanf command

#include <stdio.h> void aeins(){ int x; unsigned int y; double z; printf("Geben sie einen ganze Zahl ein: "); scanf("%d", &x); printf("Geben sie eine natrliche ...
0
votes
2answers
45 views

Scanf reads wrong value

Im new to C programming language, I have wrote a simple code that reads two char values and prints them on the screen but the second one got empty value for a strange reason. Whats going wrong ...
0
votes
0answers
33 views

need help on character reading in c programming [duplicate]

In the first int main(), scanf("%c",&z) doesn't work for some reason in that place. When I try putting it in another place, it works but that typical place doesn't work. Tried putting it in the ...
-1
votes
1answer
36 views

sscanf_s doesn't store the right pattern

I just want the string without underscore. I tried below few codes all doesn't work: string is char pointer from another function, it looks like this: " "_I_have_1_dog.dat)" " void func1(char *...
0
votes
0answers
21 views

How to switch scanf input to standard terminal input after reading input through input redirection

I need to have my program read several words from a .txt file and store them into an array using the scanf() function. However, I need to accept user input after that also using scanf. How do I ensure ...
0
votes
2answers
54 views

Weird code interaction when scanning and printing chars in C

When you declare two variables char a,b; and then you use first 'a' and then 'b',it prints only b, but if you declare it 'b' then 'a', it has no problem printing both in ASCII,the point of the program ...
0
votes
0answers
42 views

Using a ' " ' in the %[] format conversion specifier

How would I use a " in the %[] format conversion specifier in C? I have tried escaping it using the backslash escape character but this doesn't seem to work. I am trying to use %[] with fscanf (I ...
0
votes
5answers
73 views

How to stop reading input when a certain character is reached

Let's assume somebody is writing some text. My program has to scan that text and then print all the characters under each other. However, it should only read the input until * appears. So when the ...
0
votes
1answer
37 views

why does putting multiple periods for a scanf input skip the next scanf functions?

why does putting multiple periods for a scanf input skip the next scanf functions. example input: b. b. int main (void) { char b[7] = " "; printf("This is: "); scanf(" %s", b); ...
0
votes
1answer
43 views

How do I get sscanf to run in unix with a structure?

I'm trying to do as the comments state, however my sscanf statement is not working. Am I supposed to initialize the variables for dob prior to using sscanf? My program keeps giving me warnings that ...
0
votes
1answer
49 views

sscanf casting warning c

The program's purpose is to get as an input a string containing numbers and white spaces then split the string with strtok and insert every number in an array. Lastly , from the array i send the ...
-1
votes
2answers
65 views

i keep getting type-related errors

I'm writing this program for my homework and i keep getting type errors. To my knowledge %d reads integer which is in this case the variable x and %lf reads double " variable f" i've tried to remove "...