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))
			i++;
	
		line_count++;
	}
	return 0;

}

Thanks.

You are going to have to post the code you tried because we can't see your monitor.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.