Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
-1 votes
1 answer
97 views

what is the use of getchar() in following program [duplicate]

#include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #define NUM_DAYS_IN_WEEK 7 typedef struct { char *acDayName; int iDate; ...
Swathi A's user avatar
0 votes
1 answer
54 views

Problem with reading/writing on the terminal line

I am trying to write a function that reads an input from the terminal using getchar() and stores it in a string and then display it in 2 different formats. The read line should be stored in the ...
Alex's user avatar
  • 1
0 votes
2 answers
52 views

Why is it not printing the string?

I'm trying to use getchar() to read each character from the standard input and arrange it through out the array, and finally printing it. The thing is, it isn't printing the array. I've tried to use a ...
tom's user avatar
  • 1
0 votes
1 answer
287 views

Can you read in a variable length string from standard input using getchar()

I was just experimenting and wondered why my attempt did not work (the program crashes). #include <stdio.h> #include <stdlib.h> int main(int argc, char **argv) { char *list; ...
visitor's user avatar
  • 121
0 votes
4 answers
263 views

Problem reading two strings with getchar() and then printing those strings in C

This is my code for two functions in C: // Begin void readTrain(Train_t *train){ printf("Name des Zugs:"); char name[STR]; getlinee(name, STR); strcpy(train->name, name); ...
John B's user avatar
  • 23
-2 votes
1 answer
747 views

remove extra characters from a string line in c

I had an assignment to write a program that takes 2 arguments as string by getchar and saves in variables. The 2nd string defines the length of the 1st string, which means that if the first string has ...
Rosha. R's user avatar
-2 votes
1 answer
41 views

storing each word in a 2d string C

i want to store each word in a 2d string. The code i wrote is working with no errors the only issue is when there are two spaces or more, it stores the space as a word. If anyone knows how can i fix ...
Moe's user avatar
  • 17
1 vote
0 answers
205 views

Reading string from a file by using getchar

Trying to create a C program that can execute bash commands, and I'm trying to do this by reading commands from a text file. The problem I'm having is getchar is perfect for reading single characters ...
Briedis's user avatar
  • 73
1 vote
2 answers
224 views

How do I take a variable sized string as input using only getchar without asking user for string size before?

I need to collect user input with only getchar() and malloc() to store it in a string (of which the size is unknown). I've done it before but forgot how I got it right and now I'm having a problem ...
ntruter42's user avatar
  • 223
0 votes
1 answer
2k views

Program adds random characters to string in C

I am in the process of learning C, and I stumbled upon a bug, and I can't seem to get my head around it. This code is supposed to accept multiple lines of text (followed by an Enter), compare the ...
David Serb's user avatar
-1 votes
1 answer
72 views

scanf and getchar together to read string

I have this code: Hotel new_h = (Hotel*)malloc(sizeof(Hotel)); printf("\nInsert name -> "); scanf("%[^\n]s", new_h->name); getchar(); First of all, how it works %[^\n]s Why there isn't just %s ...
Davide Melis's user avatar
-2 votes
1 answer
592 views

Reading strings into 2 dimensional array in C

I want to read a number of strings from a text file (standard input) to a 2 dimensional array using getchar(). please ignore the magic number in the code. #include <stdio.h> #include <stdlib....
Andrew's user avatar
  • 1
0 votes
1 answer
127 views

getchar() loop doesn't end from no reason

I have this code snippet: char key[32]; for (int i = 0; i < 32; i++) { key[i] = getchar(); } which obviously is supposed to take in 32 characters and then stop. The problem is that it doesn't ...
Tom's user avatar
  • 125
-3 votes
1 answer
2k views

How to use getchar() with string?

I try to get a text attached to the array but this does not seem to work when I try to use printf after. It does print a blank space. char text[10][30]; // 10 is text count and 30 text length ...
Stefi Zuzu's user avatar
1 vote
1 answer
341 views

Why getchar() doesn't work but getchar_unlocked() do outside main function while reading string character wise?

Here in read() function when I use getchar() it reads only one character. It breaks the loop even if the condition in while() is true but getchar_unlocked() reads characters until given condition ...
Rajendra Chotiya's user avatar

15 30 50 per page