#include <stdio.h>
#define MAXUSERIP 5000
//
//----------------------------------------
// simple user input
void userip(char words[]) {
// userip( words);
int i=0;
int ch; // getchar returns int, use int to
// handle EOF correctly
// Read until EOF, newline, or buffer limit reached
// ch!='\0' no more user input ?ok works issue??
while (i < MAXUSERIP && (ch = getchar()) != EOF && ch != '\0') {
words[i++] = (char)ch;
// Explicitly add the null terminator safely
words[i] = '\0';
}
return ;
}
//----------------------------------------
//
int main() {
char words[MAXUSERIP + 1]; // +1 for the null terminator
userip( words);
printf("\nYou entered the words: \n %s\n", words);
return 0;
}
//----------------------------------------
//char words[MAXUSERIP + 1];
// +1 for the null terminator
//----------------------------------------
To embed this project on your website, copy the following code and paste it into your website's HTML: