#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* YT: SoftwareNuggets */
int main() {
char *token;
char delimiter[2] = {' ', '\0'};
char temp[32];
char *s = malloc(1000 * sizeof(char));
if (s == NULL) {
fprintf(stderr, "Memory allocation failed\n");
return 1;
}
if (fgets(s, 1000, stdin) == NULL) {
fprintf(stderr, "Error reading input\n");
free(s);
return 1;
}
// Remove newline character if present
size_t len = strlen(s);
if (len > 0 && s[len-1] == '\n') {
s[len-1] = '\0';
}
// Get the first token
token = strtok(s, delimiter);
// Walk through other tokens and print them
while (token != NULL) {
if(strlen(token)>0)
{
memset(temp,0,32);
strcpy(temp,token);
}
token = strtok(NULL, delimiter);
if(token != NULL)
{
printf("%s\n",temp);
}
else {
printf("%s",temp);
}
}
free(s);
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: