Skip to main content
Filter by
Sorted by
Tagged with
1 vote
1 answer
72 views

I'm using VSCode on Ubuntu 24.04.01.The screenshot shows a program that reads and displays the contents of a file. The "my_file.txt" contains the word "Hello". When I run the code ...
Lexus RX's user avatar
0 votes
1 answer
49 views

the function is supposed to return the length of a line specified by the 2nd argument but the result is either 0 or the one in the 2nd line whatever n may be: int line_length(const char *filename, int ...
Pepe Cuesta's user avatar
0 votes
1 answer
89 views

bool isIdentical(FILE *file1, FILE *file2) //this fun tell me files is identical or no { // this must have char1 in file1? char c1 = fgetc(file1); // this must have char2 in file2? ...
mazen mohamed's user avatar
0 votes
1 answer
63 views

the fgetc function in C should read just on caracter but in this code read more then one caracter . in this code i test the function fseek to move the cursur and get each time the next caracter using ...
Youssef Bouhdyd's user avatar
0 votes
0 answers
70 views

The code paragraph is as follow: fp_t=fopen(temp_name,"r"); int j=0; do { char ch=fgetc(fp_t); if(feof(fp_t)==0) all[i].note[j]=ch; j++; } while(feof(fp_t)==0); all[i].note[j-2]=...
Xiangnan Zhang's user avatar
3 votes
5 answers
174 views

I am not sure about whether I have to cast a character to an unsigned char before being compared to the return of a getc family function. The functions I consider getc family, are getc, fgetc and ...
woodenadmin's user avatar
1 vote
3 answers
114 views

This is what I have so far. The issue is that the "count" variable is not properly adding to itself when it hits a newline or space character. #include <stdio.h> #include <stdlib.h&...
quench's user avatar
  • 13
0 votes
2 answers
98 views

I'm working on my code. If I use scanf instead fgets, It works but I want to use fgets. If I use fgets after I enter number of lines, I need to press enter. How can I fix this problem? Is this normal? ...
Alpiinoo's user avatar
-1 votes
1 answer
99 views

I'm using the following code to print last N lines of one file to the other. #include <iostream> #include <fstream> #include <string> using namespace std; void printLastNLines(...
ubaabd's user avatar
  • 435
1 vote
0 answers
33 views

In my problem I was using fseek() function to read a character from the 4th position. After that I wanted to write a new character after that position where the file pointer is pointing to. As after ...
muntasir mk's user avatar
0 votes
0 answers
117 views

I have a C program running inside a Docker container and calling a function getkey() as below: int getkey() { int ch; struct termios orig_term_attr, new_term_attr; /* set terminal to raw mode */ ...
Jeff Brower's user avatar
0 votes
1 answer
164 views

I would like to understand why I can print the character 'à' with the functions fopen and fgetc when I read a .txt file but I can't assign it to a char variable and print it with the printf function. ...
ouzz's user avatar
  • 21
1 vote
1 answer
139 views

I am trying to take a list of MAC Addresses and Device names from a text file and store them in an array called list; struct list { char ch; char a[2], b[2], c[2], d[2], e[2], f[2], g[2], ...
coconut crab's user avatar
0 votes
2 answers
60 views

This code contains 3 file handling related functions which read from a file named "mno". But only the 1st called function in the main() is working. If the 1st function of the list is ...
d3v-anaxa's user avatar
0 votes
0 answers
47 views

fseek(exsist, start, end); while(count < end) { if(feof(exsist)) break; c = fgetc(exsist); printf("%c",c); if(feof(exsist)) break; ++count; ...
Nikki's user avatar
  • 29
0 votes
0 answers
47 views

So I've combed through this thing pretty thoroughly using printf statements (on mobile) and have narrowed the location of the error down to the nested if (ret == EOF) statement in the read_file ...
Jonathon Propp's user avatar
0 votes
2 answers
187 views

I'm new to C programming so if anything looks super wrong I'm sorry! I need to make my array ( str[512] ) to be exactly 512 characters long after taking input from a text file with an unknown number ...
Bananatoid's user avatar
1 vote
2 answers
129 views

I have a simple file reading algorithm but it's not returning the values that are in the file. The below is the code. The input txt values are 200 53 65 98 183 37 122 14 124 65 67 but the code is ...
evie's user avatar
  • 113
0 votes
1 answer
108 views

char *myfgets(char *s, int n, FILE *in) { char ch; if (n<=0) { return s; } while (((ch = getc(in)) != '\n')) { if(ch == EOF){ return NULL; } ...
Suki Sebastian's user avatar
0 votes
2 answers
985 views

I'm new to string and file operations in C and I have a text file file.txt with below data. I'm reading a text file which contains below information 1.#comment 2.Name="Audi" 3.Class="...
Ellariz's user avatar
  • 11
-1 votes
1 answer
770 views

I am trying to read non-printable characters from a text file, print out the characters' ASCII code, and finally write these non-printable characters into an output file. However, I have noticed that ...
Yooshinhee's user avatar
1 vote
2 answers
1k views

I am reading data from a regular file and I was wondering which would allow for the most flexibility. I have found that both fgets and getline both read in a line (one with a maximum number of ...
tintins7a6164's user avatar
8 votes
3 answers
2k views

Certainly fgetc() returns EOF when end-of-file or an input error occurs. Is that all and does that mean no more data is available? FILE *inf = ...; int ch; while ((ch = fgetc(inf)) != EOF) { ; } if (...
chux's user avatar
  • 158k
1 vote
2 answers
200 views

I'm trying to print line numbers in the beginning of the lines without using fgets() yes, it prints line number well when I input multiple files but I want to get result like this. Can you guys help ...
dreamingsoftwareegineer's user avatar
0 votes
0 answers
36 views

I'm trying to code a little program to sort words frome a .txt file. I use Dev-C++ 5.11 as IDE with GCC 4.9.2. Below, the .txt file content: aaa ert ert ert zzzz aaa zzzz # ert ert #xxx I have to ...
dhiya-eddine Nadour's user avatar
0 votes
0 answers
226 views

Here is the logic what I am trying to do; get input char with fgetc() in the variable named ch, check if not ch is EOF or equal to '\n', increase int variable named counter, then put the variable ch ...
erugersauzu's user avatar
0 votes
1 answer
1k views

I have a txt file of this form: 11 10 BU 1U 0U 0U ... I would like to read each digit/character one by one from the file in C. The first two rows contain 2 integers, the rest of the rows contain ...
Tryer outer's user avatar
1 vote
1 answer
294 views

I'm coding a small game and i decided to load a map from the file but I'm facing a problem.The file looks like this : and i need to print it like it is in the file expect of dots. They has to be ...
Jakub Kolesár's user avatar
1 vote
1 answer
1k views

I'm trying to write a program that : open a txt files read the first word of a line and store it in a variable (or an array) => it'll be a name read the second word of a line and store it in a var/...
user avatar
0 votes
1 answer
366 views

I'm trying to write a specific program that reads data from a file but I realized that when I read the file with fgetc, if I use fgets later, it doesn't have any output. For example, this code: #...
Jonas's user avatar
  • 468
0 votes
0 answers
40 views

I'm trying to write a program that asks for input of the name of a file and a char to be counted inside the file. But whenever I input the proper name of a file (like, "file.txt") it jumps ...
Jonas's user avatar
  • 468
0 votes
2 answers
95 views

#include <stdio.h> int main () { FILE *fp; int c; fp = fopen("file.txt","r"); while(1) { c = fgetc(fp); if( feof(fp) ) { break ; ...
bruceherring's user avatar
2 votes
1 answer
307 views

In C, there are many posts concerning using fgetc after fscanf, dealing with an additional \n, but I am seeing another issue when using them in the reverse order; fscanf after fgetc. When using fscanf ...
foam78's user avatar
  • 284
0 votes
1 answer
408 views

My aim is to find the encoding of a text file by dividing the size of the file by the number of characters in the file. but fgetc only reads UTF8 encoded files. not working for UTF16. Kindly help me ...
Mohamed Ibrahim Ansari's user avatar
0 votes
1 answer
811 views

So I'm working on a project, and I need to check whether or not a certain file contains the contents of another file. I made a function in c (It's c not c++) to try and to it but it seems to get into ...
איתן טורפז's user avatar
0 votes
2 answers
259 views

I have a .txt file where every line is like: id name surname 78 99 101 12 33 44 Every line I need to fill a struct of Student. The numbers after surname have to be stored in an array of structs ...
user avatar
1 vote
2 answers
406 views

My .txt file I have created before running the code looks like the following: /* I am Jason and I love horses hahaha/n This is amazing, How much I love horses, I think I am in love/n how many people ...
Jason Hwang's user avatar
0 votes
0 answers
241 views

I have tried to read a binary file from end using fseek() to move the cursor to the end and fgetc() to read the file. fseek(fptr, 0, SEEK_END); int size = ftell(fptr); unsigned char c; int i =0; ...
Hera's user avatar
  • 1
1 vote
1 answer
979 views

I'm writing a C Program that changes all uppercase characters to lowercase from a certain file. The problem is, after storing all characters (processed) in a string, and trying to print all characters ...
Mateaș Mario's user avatar
0 votes
1 answer
133 views

I am trying to read text in a file and store it in a string so that it can be output and read although when I try to see the output string it seems to have a completely different output. does anyone ...
George Sayles's user avatar
1 vote
1 answer
544 views

I'm trying to make a program that concatenates multiple files to one. The code that i currently have is the following: #include <string.h> #include <stdio.h> void main(int n, char** args) ...
TopchetoEU's user avatar
3 votes
2 answers
670 views

When running the following C file, copying the character to fgetc to my tmp pointer results in unknown characters being copied over for some reason. The characters received from fgetc() are the ...
connorwmackay's user avatar
1 vote
1 answer
126 views

I'm trying to get the fgetc command working in a very simple for loop. While (pun intended) it works in a while loop it doesn't work in a for loop and I can't figure why. It should just grab whatever ...
Joesns's user avatar
  • 45
0 votes
0 answers
67 views

I'm reading a .pgm file (like the lines below) with "fgetc(file)". When getting only the numbers with a loop in which I avoid the spaces in between (it seems it treats each space, no matter ...
DoZmeR's user avatar
  • 11
0 votes
1 answer
256 views

std::string sQuery; char ch= NULL; ch = fgetc(stdin); if(ch != EOF) { sQuery += ch; } checkmarx is complaining about the code saying that fgetc element gets database data and element value flows ...
srikanth noti's user avatar
0 votes
3 answers
85 views

I'm running into trouble where on a release build I'm losing about 7-8MB/s of throughput due to a simple case statement: switch(ch) { case '\t': // tab m_column+=TabWidth; // tabwidth is ...
honey the codewitch's user avatar
1 vote
2 answers
106 views

First, let me say that I apologize for the lack of specificity in this title. There honestly was no good way to describe what I encountered in a single sentence to be honest, but I will try to ...
AndyP's user avatar
  • 13
0 votes
2 answers
269 views

I am trying to push numbers from a text file into a linked list which might have multiple digit numbers in multiple lines. My output is a mess, only printing -47 multiple times. My main doubts are how ...
crayon's user avatar
  • 113
0 votes
1 answer
188 views

For my algorithm, I would like to backtrack after going through all the chars in a file back to specific index char. For example, I have a file with ABCDEF, I want to access in the order ABCDEF then ...
Jimmyman123's user avatar
0 votes
0 answers
210 views

I am trying to build my own lineread method to read a file line by line using a filedes, a buffer and a size parameter. My reasoning is that I can read the file using 1 as my size to go through every ...
Yohan's user avatar
  • 45

1
2 3 4 5 6