#include <stdio.h>
#include <string.h>
#define MAX_WORDS 32
#define MAX_LEN 256
void remove_middle_word(char *str) {
char *words[MAX_WORDS];
int count = 0;
// Split into words
char *token = strtok(str, " ");
while (token != NULL && count < MAX_WORDS) {
words[count++] = token;
token = strtok(NULL, " ");
}
if (count <= 2)
return;
int mid = count / 2;
// Use a separate buffer for output
char result[MAX_LEN] = "";
for (int i = 0; i < count; i++) {
if (i == mid) continue;
if (result[0] != '\0')
strcat(result, " ");
strcat(result, words[i]);
}
// Copy result back into original buffer
strcpy(str, result);
}
int main() {
char str[MAX_LEN] = "c c++ java rust python";
remove_middle_word(str);
printf("%s\n", str);
return 0;
}
/*
run:
c c++ rust python
*/