Questions tagged [putchar]

Anything related to C or C++ standard library functions `putchar` (C) or `std::putchar` (C++). These functions are used to write a single character to the standard output stream `stdout`.

Anything related to C or C++ standard library functions putchar (defined in <stdio.h> C standard header) or std::putchar (defined in <cstdio> C++ standard header). These functions are used to write a single character to the standard output stream stdout.

See CPPreference.com:

175 questions
0
votes
2 answers

3 digit generator in C

I'm trying to generate every possible 3-digit combination like: 012, 013 ,014... BUT: I want to ignore repeated characters (like 999 or 022) and I also don't want to re-use numbers (if 123 already there, don't display 321) so, the last value should…
John Konolol
  • 69
  • 1
  • 9
0
votes
1 answer

displaying contents of a file on monitor in C

I'm trying to recreate a program I saw in class. The teacher made a file with 10 lines, he showed us that the file was indeed created, and then he displayed its contents. My code doesn't work for some reason, it just prints what looks like a"=" a…
Oria Gruber
  • 1,513
  • 2
  • 22
  • 44
0
votes
4 answers

Output not displayed with usleep until a line break is given

I'm trying to program a simple "typewriter" effect in C, where text appears one letter at a time with a delay. Here's the function I have: #include #include void typestring(const char *str, useconds_t delay) { while (*str)…
flarn2006
  • 1,787
  • 15
  • 37
0
votes
4 answers

Why doesn't this eliminate double spaces in C? It's one of the getchar() exercises in K & R

This is a K&R exercise. It's supposed to substitute a single space for double or more. Instead it exactly mirrors input, spaces and all. Also, why do I have to use EOF (ctrl-d) in other exercises and RETURN (Enter) for this one? (I'm running it on…
0
votes
2 answers

Output coming out as an upside down question mark and prompt is coming out twice in calculator program in C

I'm writing a simple calculation program and I can't get any valid output. All I'm getting is an upside down question mark. Also, I have a prompt at the end of the program to ask the user if they would like to enter in another calculation. However,…
user1681673
  • 368
  • 1
  • 6
  • 28
0
votes
2 answers

Is there potentially an endianness trouble here?

I would like to write a function such as putchar, with the help of write function. #include ssize_t f(int fd, int c) { return write(fd, &c, 1); } But I think there could be an endianness problem here, isn't it ? So should I use…
md5
  • 23,373
  • 3
  • 44
  • 93
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
0
votes
4 answers

C Programming (Beginner help) relating to getchar() putchar()

Im new to C programming and wanted to clear, what may seem to be, a silly doubt... Code: #define EOF 0 main() { int c; c=getchar(); while (c!= EOF) { putchar (c); c= getchar(); } } this should just return the…
Aki
  • 15
  • 5
0
votes
4 answers

ANSI C - Replacing blank characters without using arrays

I've started studying "The ANSI C Programming Language" by Dennis Ritchie and Brian W.Kernighan. So far I've just learned getchar(),putchar(),while, for, if. There is an exercise that I have to do only using what I've learned by now. The above are…
Mikayil Abdullayev
  • 12,117
  • 26
  • 122
  • 206
0
votes
3 answers

Segmentation fault when running C program (putchar() and multidimensional array pointers)

I'm trying to run the following code on C: #include "ex1_1.h" void path(char **adj_mat, int u, int v) { printf("test\n"); char temp = *adj_mat[1]; putchar(temp); } int main() { int u = 5; int v = 5; char…
judith
  • 805
  • 2
  • 12
  • 17
-1
votes
2 answers

Replace each string of one or more blanks with a single blank

This was already asked, but I made my own program and I don't know why it doesn't work. int c; char blank; while ((c = getchar()) != EOF) { if (c == ' ') { putchar(c); while ((c = getchar()) == ' ') { putchar(''); …
-1
votes
1 answer

strlen of char array & putchar

I am compiling and running this code: // hello, world!, without printf #include #include char a[7] = "hello, "; char b[7] = "world!\n"; void putCharArray(char *ray) { for (int i = 0 ; i < strlen(ray) ; i++ ) {…
-1
votes
2 answers

Nonsensical output stream during the usage of "getchar()" and "EOF"

I have been experimenting with getchar(), putchar() and have been trying to use EOF. Below is the snippet of code I have been experimenting with. #include int main(void) { int c; c = getchar(); while(c != EOF) { …
Swarnim Khosla
  • 117
  • 1
  • 10
-1
votes
1 answer

how to create each word of input to start a new line

Hey i am trying to print each word on a new line. My EOF is also not working and was wondering why this is. i have made it to scan for a space and then print new line. #include #include int main(void) { char ch; while…
J.K
  • 1
  • 3
-1
votes
1 answer

Getting input with fgets and outputing the answer in reverse with recursion

This is a sample snippet from a book. I am not understanding how it is printing the string in reverse. The first time reverse is called, the element at 0 is not null assuming of course a valid string was entered. In the else statement, we are…
Kinozato
  • 13
  • 1
  • 6