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
0
votes
1 answer

User input to make a linked list

I have a project for a c 99 programming class that requires us to ask a user for a sentence and then take that sentence char-by-char and store each char individually in a linked list. We were told that we need to use getc() and a while loop to read…
0
votes
3 answers

Tokenizing user input in C (store in **arg)?

I'm attempting to write a simple shell like interface, that takes in a users input (by char) and stores it via a pointer to a pointer* (exactly how argv works). Here's my code: char input[100]; char **argvInput; char ch; int charLoop = 0; int…
Justin H.
  • 23
  • 2
0
votes
2 answers

Capturing the return/enter as keystroke to quit program

This program reads in a file and then asks the user to enter a number of lines to be displayed. After the number of lines have been displayed, the user is prompted again for either more lines to be printed or to quit by pressing return. I'm having…
blitzeus
  • 485
  • 2
  • 10
  • 28
0
votes
2 answers

Unknown Logical Error Using the getc() Function in C

I'm attempting to use the getc() function to copy the contents of one file into another. But I'm making an unknown logical error because the output of the following program is a bunch of garbage. #include #include #include…
user800786
0
votes
2 answers

Know the row with max characters (C)

I have written a program in C, to find the row with the max number of characters. Here is the code: #include #include #include #include int main (int argc, char *argv[]) { char c; …
Lc0rE
  • 2,236
  • 8
  • 26
  • 34
0
votes
1 answer

Replace a character with "argv[2]"

I have some code here: #include #include #include #include int main (int argc, char *argv[]) { char c; FILE *fp; fp = fopen(argv[1], "r"); if (fp == NULL) …
Lc0rE
  • 2,236
  • 8
  • 26
  • 34
-1
votes
2 answers

Issues with do/while loop ask question too many times

I have a problem with my code: When I write any input different from 1,2,3,4 the output is Inserire il numero dei giocatori inserire un numero valido Inserire il numero dei giocatori inserire un numero valido Inserire il numero dei giocatori How…
-1
votes
2 answers

C Programming , getc() , stdin , file redirection

My assignment is to redirect a text file and do all sorts of operations on it , everything is working except I have a little problem : so the main function that reads input is getline1(): char* getline1(){ char *LinePtr =…
-1
votes
1 answer

A special Segmentation fault,I don't know why

#include int main(){ int count[26]; for(int i=0;i<26;i++){ count[i]=0; } printf("xx1"); FILE *p; printf("xx"); p=fopen("test.txt","r"); if(p==NULL) printf("error"); int x=fgetc(p); …
P.rong
  • 1
  • 1
-1
votes
1 answer

C: getc returns -1

The problem I have is in this line: int tok = getc(fp); getc returns -1. Why? Thanks in advance. #include #include #include "file_reader.h" /** * Opens a text file and reads the file. The text of the file is stored * in…
Yuehai
  • 1,165
  • 1
  • 10
  • 20
-1
votes
1 answer

Why testing for the sign of the int is called "sloppy code" in glibc reference?

In glibc reference we find such words: ...sloppy code like { int c; ... while ((c = getc (fp)) < 0) ... } has to be rewritten... Why testing for the sign of the int is called "sloppy code" in glibc reference?
Igor Liferenko
  • 1,499
  • 1
  • 13
  • 28
-1
votes
1 answer

reading characters from buffer

I am scanning strings as input , i am using getline to do so e.g char *lajna=NULL; size_t dlzka=0; getline(&lajna,&dlzka,stdin); and i want to read first char using fgetc , i tried to do test=fgetc(lajna); but it throws error cannot convert…
Johnyb
  • 980
  • 1
  • 12
  • 27
-1
votes
1 answer

Printing the contents of a file using getc and putc

I've seen this question has been asked before, but none of the answers seemed to work for my problem. I am attempting to write a function that will read the contents of a file, and print them. Here is my code; int main() { int c; …
SexRobomb
  • 5
  • 1
  • 2
-1
votes
1 answer

getc function not reading '\n'

I want the function to print a 0 whenever it reaches a new line but it's not working but getting each word from file works fine. A speedy response would be appreciated. The data in the input file looks like this: blossom flower bewilder confound…
PinC
  • 9
  • 1
  • 6
-2
votes
3 answers

Test the space in a string from a file

I am trying to test if the character in a file.txt is a space ' ' or not using this code: char *Appartient (FILE *f, char *S) { int i = 0, nbdechar = 0, nbocc = 0, PosdePremierChar, space = 0; char c; while ((c = getc(f)) != EOF) { …
Programmer
  • 54
  • 1
  • 2
  • 9