How To Remove Spaces In A Text Then Put Them

[Solved] How To Remove Spaces In A Text Then Put Them | Swift - Code Explorer | yomemimo.com
Question : how to remove spaces in a text then put them into a single word each by each in c programming using pointer without using string functions

Answered by : clean-crocodile-qqkdznxybprs

#include <stdio.h>
#define MAX_TEXT_LENGTH 100
#define MAX_WORD_LENGTH 20
void removeSpaces(char* text) { char word[MAX_WORD_LENGTH]; char* wordPtr = word; while (*text != '\0') { if (*text != ' ') { *wordPtr = *text; wordPtr++; } else { if (wordPtr != word) { *wordPtr = '\0'; printf("%s\n", word); wordPtr = word; } } text++; } if (wordPtr != word) { *wordPtr = '\0'; printf("%s\n", word); }
}
int main() { char text[MAX_TEXT_LENGTH]; printf("Enter a text: "); fgets(text, sizeof(text), stdin); printf("Words without spaces:\n"); removeSpaces(text); return 0;
}

Source : https://chat.openai.com/ | Last Update : Sat, 01 Jul 23

Answers related to how to remove spaces in a text then put them into a single word each by each in c programming using pointer without using string functions

Code Explorer Popular Question For Swift