answersLogoWhite

0


Best Answer

#include <stdio.h>

#include <string.h>

/* To read something into a string in C you would do the following: */

char * str;

str = malloc(100 * sizeof(char));

scanf("%s", &str);

/* Another way to do the same thing is to read character by character: */

for(int i = 0; (i < 100) && (*(str + i) != '\n') ; i++)

scanf("%c", str + i);

/* This code told the computer to keep reading into str until the computer reads a '\n'

or until the computer reads 100 characters (which is how much I mallocated for str) */

/* Changing the '\n' to 'q' means keep reading and don't stop until you find a 'q'

User Avatar

Wiki User

15y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you read more than one line in C?
Write your answer...
Submit
Still have questions?
magnify glass
imp