Skip to content

Instantly share code, notes, and snippets.

@unlight
Created November 1, 2012 19:51
Show Gist options
  • Select an option

  • Save unlight/3996017 to your computer and use it in GitHub Desktop.

Select an option

Save unlight/3996017 to your computer and use it in GitHub Desktop.
Reverse words
#include <stdio.h>
#include <conio.h>
#include <string.h>
int main()
{
char String[255];
char* Words[50];
char* Pchar;
char Delimeter[] = " .,!";
int Index = 0;
if (strlen(String) <= 2) {
printf("String: ");
gets(String);
} else {
printf("String: %s\n", String);
}
Pchar = strtok(String, Delimeter);
while (Pchar != NULL) {
Words[Index] = Pchar;
Pchar = strtok(NULL, Delimeter);
Index++;
}
while (Index > 0) {
Index--;
printf("'%s'", Words[Index]);
if (Index != 0) printf(", ");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment