hey guys, finished off most of this code. I believe I should be using strcmp to compare the two newly tokenized strings and put the first alphabatized string first.
Need help with part 4
example input
this is a string
output
a
is
string
this
any help is greatly appreciated
Code:
#include <stdio.h>
#include <string.h>
void RecursiveReverse(const char *const sPtr);
int main()
{
/*Part One*/
char buffer1 [] = {'T','h','i','s',' ','i','s',' ','a',' ','l','o','o','p','\0'};
char buffer2 [] = {"This is the second buffer"};
char buffer3 [80];
char buffer4 [100];
char buffer5 [100];
char *tokenptr;
// char *tokenptr1;
gets(buffer3);
printf("\n%s\n", buffer1);
printf("%s\n", buffer2);
/*Part 2*/
char *pb;
pb = buffer3;
while(*pb != '\0'){
printf("%c", *pb);
pb++;
}
printf("\n");
/*Part Three*/
printf("The line to print:\n");
gets(buffer4);
printf("The new line is:\n");
RecursiveReverse(buffer4);
printf("\n");
/*Part 4*/
printf("Please enter the string to be parsed:\n");
gets(buffer5);
printf("\n");
tokenptr = strtok(buffer5, " ,"); /*Begins tokenizing*/
while(tokenptr != NULL){
printf("%s\n", tokenptr);
tokenptr = strtok(NULL, " ,"); /*Gets next token*/
}
printf("\n");
// while(tokenprt != NULL)
return 0;
}
void RecursiveReverse(const char *const sPtr)
{
if (sPtr[0] == '\0'){
return;
}
else{
RecursiveReverse(&sPtr[1]);
putchar(sPtr[0]);
}
}