Questions tagged [getc]

Anything related to C or C++ standard library functions `getc` (C) or `std::getc` (C++). These functions are used to read a single character from a stream.

Anything related to C or C++ standard library functions getc (defined in <stdio.h> C standard header) or std::getc (defined in <cstdio> C++ standard header). These functions are used to read a single character from a stream and they can also be implemented as C-preprocessor macros.

See CPPreference.com:

91 questions
2
votes
1 answer

Inserting into a dynamic character array while using realloc()

I am very much wanting to catch up on my C programming skills, so I have started my own self-training program, attempting to reading files and inserting their contents into different data structures. Here, I am wanting to use specifically a…
PluffTed
  • 53
  • 5
2
votes
1 answer

Input of maximum 256 characters in C

I/O question: I was asked to get an input from the user and parse it. The problem is my program is supposed to be able to handle any length of input and to treat any input line longer than 256 characters as invalid and print a message accordingly.…
Amit
  • 55
  • 1
  • 6
2
votes
1 answer

perl6 what is the best way to enter multiple multi-line here-docs from $*IN

I need to enter multiple HERE-DOCs. My codes have 2 while loops. The inner loop is used to get the multi-line here-doc. But after I enter Control-D to complete one here-doc, then the inner while loop does not run again and the outer loop runs…
lisprogtor
  • 5,677
  • 11
  • 17
2
votes
1 answer

C: How to use getc to avoid non UTF-8 characters being produced?

I'm currently writing a c program that will take 3 arguments, two files (one input and one output) and an int (the max length of output lines, call it x). I want to read every line in the input file and write the first x characters to the output…
rafro4
  • 65
  • 7
2
votes
1 answer

reading through a dict file finding "words" and add into trie

For this problem I have to read through a and distinguish what a word is. A word does not need to be meaningful, ie. a word can be asdas,sdgsgd,dog,sweet and etc... To access the I must do it through a mapping file. File *map, *dictfile,…
bkennedy
  • 403
  • 1
  • 4
  • 17
2
votes
2 answers

Read from a file using getc and print using putc

I'm trying to read each character from a file and print it to the screen using getc and putc alone. Here's my code, FILE *fp = fopen("new.txt","r+"); rewind(fp); while( feof(fp) == 0 ) { putc( getc(fp) , stdout); } When ever I execute this,…
kesari
  • 536
  • 1
  • 6
  • 16
2
votes
1 answer

How to read past EOF from getc?

I am writing a XOR encryption program which works fine during encryption but during decryption the char ca2=fgetc(f); gets stuck at one point and no decryption takes place after that my best guess about the problem is (the encrypted file…
user1232296
  • 217
  • 2
  • 6
2
votes
1 answer

checking chars when reading from file with getc

In the following code, I'm attempting to store all characters from a file (including newlines). If a newline is read, variable 'i' should be incremented and 'j' reset to 0, but this doesn't happen. I've confirmed that the newlines are in fact being…
kensing
  • 95
  • 1
  • 1
  • 8
2
votes
2 answers

IO::Handle to get and unget unicode characters

I think I've run into a problem with Unicode and IO::Handle. It's very likely I'm doing something wrong. I want to get and unget individual unicode characters (not bytes) from an IO::Handle. But I'm getting a surprising…
Michael
  • 8,446
  • 4
  • 26
  • 36
1
vote
0 answers

Perl's getc issue in SIGINT handler in perl 5.14.2

Here is my testing environment: root@redhat89195 bin]# ./perl -v This is perl 5, version 14, subversion 2 (v5.14.2) built for x86_64-linux-thread-multi ..... Code snippet: $SIG{INT}=sub{ print "1234\n"; print getc(STDIN); …
1
vote
4 answers

how to make arrays from txt file C

I got text file with information: (100;200;first).Can anybody tell me how to seperate this information into three arrays: Min=100,Max=200 and Name=first. I have tried this whith c=getc(inp); i=atoi(szinput); but its read 10 for first time and 00 for…
user997863
1
vote
1 answer

Reading only .txt files from an input directory, then getc all contents into one array in C

So I am attempting to make a function that receives an input directory, examine only its ".txt" files and then store ALL contents into one character array (dynamically allocated, here). As I use getc() on every character in each file, one at a…
PluffTed
  • 53
  • 5
1
vote
0 answers

How to signal an error in a file for ferror

Suppose I have this code: FILE *myfile=fopen("myfile.txt", "r"); if (!myfile) {...} while (1) { int c = getc(myfile); if (ferror (myfile)) { perror ("get c error"); exit (EXIT_FAILURE); } else if (c == EOF){ printf ("%s\n" ,…
kali
  • 141
  • 10
1
vote
1 answer

getc() skips first value of text file (C)

I am trying to read a text file separated by semicolons such as 3;7;9; 4;7;23; However, every time I call while ((c = getc(fp))!= EOF) putchar(c); it skips the first value (3) and only outputs: ;7;9; 4;7;23; Is there any way to get the…
GenieB
  • 11
  • 1
1
vote
2 answers

What is wrong with this code of file handling in c?

I am trying to write content in a file from terminal. File is creating but content is not written into the file. #include #include #include int main(int argc, char *argv[]) { FILE *fp; …
Shubham D
  • 79
  • 1
  • 7