I have a weird situation. Suppose a string will be entered as an input. using the getchar() function i count the number of characters the string contains until a new line character is encountered. So i know the size of the string. And then i try to allocate enough memory dynamically to hold that string(itz possible since i know the size). After that i need to read that string again from the console(but the user should enter it only once) and put it in the allocated memory. I just want to know if theres any way i can read an input twice from the console. I know there are other ways i can solve my problem for e.g while i count each character i can write that in a file and later i can read the string from the file anytime i want. But i would like to know if i can read same input twice from the console, and if so how.
Jump to Post
>I just want to know if theres any way i can read an input twice from the console.
The only portable way is to ask the user for the same input again. Once you read data from stdin, it's gone unless you saved it. Another option (you can decide if …
Jump to Post
>but i think saving it into a file is much a easier process
Far less efficient though. Device I/O is about as slow as it gets aside from interactive input.
>So theres actually no way to read things back from console, i reckon.
Not unless the terminal stream supports …
All 6 Replies
We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.