Alright, heres the thing, this assignment for school is due in like 3 days, i have spent so much time staring at my code and i dont know whats wrong!! the problem is in the function, i know that for sure, something about mabey using strlan...
This is what i have so far... its almost finished, just a few small changes is all i need, and im sure its a totally obvious problem, but i only started learning C two and a half weeks ago, so were all going to place pity on the beginners, right?? haha...
//Alicia Hogue
//Chapitre 8
//Exercise 8.13
//this program takes an inputted sentance in english and
//translates it to "pig latin". Taking the first letter of each word
//place it at the end of each word in the sentance, followed
//by "ay".
#include <stdio.h>
#include <string.h>
#include <conio.h>
void PrintLatinWord(char *word);
int main(void)
{
char sentance[255];
char array1[255];
char array2[255];
char *delimiters=array1;
char *token=array2;
strcpy(delimiters, " ");
printf("Please enter a sentance to be translated:\n");
gets(sentance);
token = strtok(sentance, delimiters);
while (token != NULL)
{
PrintLatinWord(token);
printf("%s\n",token);
token = strtok(NULL, delimiters);
printf("%p\n", token);
getch();
}
return 0;
}
void PrintLatinWord(char *word)
{
int flag=0, i=0;
char temp=word[0];
char *tptr=&temp;
while(!flag)
{
word[i]=word[i+1];
//shifts every character one over to the left
if (word[i]=='\0')
flag++;
i++;
}
strcat(word,tptr);
//adds the first letter tp the end
strcat(word,"ay");
}
oh, and if you see any other errors in the code you can feel free to point them out as well...thanx!



LinkBack URL
About LinkBacks
thanx! 


