supposed to declare a string of a certain size (eg. char str[81])
Then input a string from the keyboard (spaces included) using the while (NOT, gets(), or fgets()) technique (while ((str = getchar()) != '\n')) adjusted so that it only inputs a certain number of characters (in the above example that would be 80, not 81). not that the number of characters need to be a variable, not a constant
be sure that there's a null in the proper location once the input is done. And we will be entering 5 seperate strings to all be placed into this character array.

Ive taken a crack at this and just cannot seem to adjust the while loop to allow only an input of 80 characters from the user, so the array is filled but not going over the limit. ive tried using strlen(str) and ect other examples but cannot find a way to do it.

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <ctype.h>

int main (void)
	char str[81];
	int i = 0, line_count = 0;
	while (line_count < 5)
		printf("Please enter a string no less than 15 characters:");
		while ((str[i] = getchar()) != '\0' && i < strlen(str))
	return 0;



Edited by atramposch: n/a

6 Years
Discussion Span
Last Post by Ancient Dragon
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.