300 questions
- Bountied 0
- Unanswered
- Frequent
- Score
- Trending
- Week
- Month
- Unanswered (my tags)
1
vote
1
answer
74
views
VS Code. File contents are not displayed in TERMINAL and OUTPUT
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 ...
0
votes
1
answer
49
views
function to return number of characters in n line of a file return always those of line 2 in c
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 ...
0
votes
1
answer
89
views
Why does this code print null characters and why does it find null characters in both files? [closed]
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?
...
0
votes
1
answer
63
views
fgetc reading file in C
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 ...
0
votes
0
answers
71
views
About fgetc() in C
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]=...
3
votes
5
answers
174
views
Does a character have to be casted to unsigned char before being compared to getc family returns?
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 ...
1
vote
3
answers
115
views
I'm trying to read text from a .txt file and count the amount of words in it using c
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&...
0
votes
2
answers
99
views
fgets() waiting input for file write [duplicate]
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? ...
-1
votes
1
answer
100
views
`fseek` issue when printing last $N$ lines to a file using C++
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(...
1
vote
0
answers
33
views
Why do I need to add one more fseek() function in my code after fgetc() function? [duplicate]
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 ...
0
votes
0
answers
118
views
C program inside docker container ignores fgetc(stdin)
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 */
...
0
votes
1
answer
164
views
Unable to print the character 'à' with the printf function in C
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.
...
1
vote
1
answer
140
views
Storing mac addresses and device names listed in a text file into a struct array using C
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], ...
0
votes
2
answers
60
views
why does only the 1st file reading function executes over multiple programs of the same kind in C language?
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 ...
0
votes
0
answers
47
views
Fseek a txt to print by character using fgetc
fseek(exsist, start, end);
while(count < end)
{
if(feof(exsist)) break;
c = fgetc(exsist);
printf("%c",c);
if(feof(exsist)) break;
++count;
...