#include <stdio.h>
#include <string.h>
// Function to truncate the last word in a space-separated string
void removeLastWord(char *src, char *dest) {
int i = 0;
char *p = NULL;
strcpy(dest, src);
// Find the last space in the string
while (dest[i]) {
if (dest[i] == ' ')
p = &dest[i];
i++;
}
// If a space was found, truncate the string there
if (p != NULL)
*p = '\0';
}
int main(void)
{
char s[32] = "c c++ c# java python";
char tmp[32] = "";
// Call the function to truncate the last word
removeLastWord(s, tmp);
// Print the result
printf("%s\n", tmp);
return 0;
}
/*
run:
c c++ c# java
*/