• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 394
  • Last Modified:

Program requiring strings, writing to a file, analyzing text, converting text and writing to another file and then finally printing results onto screen.

My program consists of strings, creating a file, write a char string and store it into the file, converting the char string then printing results onto the screen.

There are a number functions that need to be used.

The user is asked to input a sentence and then sentence is translated into another language.

It is truely one of the toughest ones I've come accross and I just can't seem the grasp the whole strings portion of C and its becoming a mess right now.


Here is my program:


#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define MAX 90

void DisplayRules( );
int Menu(int select);
int FindNonBlank(char sentenceIn[ ], int count);
int FindBlank(char sentenceIn[ ], int count);
void copyWord(char sentenceIn[ ], char word[ ], int b, int e);
int DetermineRule(char word[ ]);
void ApplyRule0(char newWord[ ], char word[ ]);
void ApplyRule1(char newWord[ ], char word[ ]);
void ApplyRule2(char newWord[ ], char word[ ]);
void CreateSentenceOut(char sentenceOut[], char newWord[]);

int main()
{
      char sentenceIn[MAX];
      char trash;
      int select;
      char word[max]=;
      char newWord[max];
      char sentenceOut[max];
      int b=0, e=0;


      printf ("\nEnter 1 to Quit anything else to continue > ");
      select = Menu( );

      while(select != 1)
      {
            printf("Enter a sentence: ");

            scanf("%c",&trash);//uses up the '\n' from the buffer
            gets(sentence);

            printf("\n%s\n", sentence);

            printf ("\nEnter 1 to Quit anything else to continue > ");
            select = Menu( );
            FindNextNonBlank(sentenceIn,i);
            FindNextBlank(sentenceIn,nextNonBlank);
            copyWord(sentenceIn,word,nextNonBlank,nextBlank);
            CreateSentenceOut(sentenceOut, newWord);
            i=nextBlank;

      }
      printf("\nGOODBYE!\n\n");
      return 0;

}

int Menu(int select)
{
      int select;
      scanf("%d", &select);
      return(select);
}

int DetermineRule(char word[ ])
{
      char letter[3];

      letters[0] = word[0];
      letters[1] = word[1];
      toupper[letters[0];

      while(letters[0]=='A'||letters[0]=='E'||
              letters[0]=='I'||letters[0]=='O'||
              letters[0]=='U')

      
      return(0);
}

int FindNonBlank(char SI[ ], int i)
{
      while(SI[i]==' ')

      i++;

      return (i);
}

int FindBlank(char SI[ ], int i)
{
      while(SI[i]==' ')
      {
            if(SI[i]=='\0')
            return(i);
      }
      i++;

      size = nextBlank - nextNonBlank;

      strncat(word, &SI[nextNonBlank], size);

      i=nextBlank;

}


void DisplayRules()
{
      printf("Hello and thank you for using my language conversion program.\n");
      printf("Before we continue we need to provide some rules. First when\n");
      printf("being asked to type in your sentence, please refrane from using\n");
      printf("from using such symbols as: !@#$%^&*()__+=\[]{};':/<>? and etc.\n");
      printf("If you follow that rule your sentence will run flawlessly! Have\n");
      printf("fun and enjoy the wonders of what piglatin has brought to the world!\n\n\n\n");

}


-------------------------------------------------


This is obviously in preliminary status but it should give you some idea as to what Im aiming at.


0
Redevo7
Asked:
Redevo7
  • 18
  • 7
  • 4
  • +3
1 Solution
 
Redevo7Author Commented:
I know there are errors and such but I just want to know if Im not doing this correctly so far.


Also the words are being translated into piglatin.


Here is an example of an input:

THERE IS AN APPLE HERE

Output:

ERETHAY ISAY ANAY APPLEAY EREHAY

Maybe I should give you a rough idea of my algorithms?


From what I am getting at is we should store the users sentence into the file, analyze it and apply conditions, convert it and store it into another file and finally print the results.
0
 
rajeev_devinCommented:
Lots of compilation errors:

Corrected declarations
char sentenceIn[MAX];
char trash;
int select;
char word[MAX];
char newWord[MAX];
char sentenceOut[MAX];
char sentence[MAX];

>> int Menu(int select);
But you are using like
int select = Menu();
Remove the parameter from Menu. Make it
int Menu();
0
 
rajeev_devinCommented:
>> FindNextNonBlank
Where is this function? It is not defined.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
rajeev_devinCommented:
>> FindNextBlank
It is also not defined.
0
 
rajeev_devinCommented:
Post the corrected code.
0
 
tushar_compCommented:
i think there are lot of problems
u r  scanning trash then passing sentence as parameter to function?
why ??

there are lot of updations required
if u want me to do so
reaply
Tushar...
0
 
PaulCaswellCommented:
tushar_comp,

>>... if u want me to do so ...
It is very tempting to just fix the problem. Please remember not to as this is homework. We must help them find their answer.

Paul
Page Editor
0
 
Infinity08Commented:
>> and its becoming a mess right now.
don't ever let your code become a mess, because that's exactly the cause of your problems.

Split the task up into small parts, and take them on ONE AT A TIME. Get each part working, before adding the next.

The title of your question already shows the different sub-parts of what you need :

  * strings
  * writing to a file
  * analyzing text
  * converting text
  * writing to another file
  * printing results onto screen

Try to find out how to do these separately, get each part to work (understand how), and then combine everything into one nice program.
0
 
Redevo7Author Commented:
That is true as I only have some problems in certain areas. I need to help write my algorithms and Ill post which are my problem areas.
0
 
Redevo7Author Commented:
Alright I started my program over and I am trying to work step by step making sure I have my functions working and my string commands working correctly. What I've done is printed the last step as to where I am at.

--------------------------------------------------------------------------------------

#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define MAX 80


void DisplayRules( );
int Menu();
int NextNonBlank(char sentenceIn[ ], int count);
int NextBlank(char sentenceIn[ ], int count);
void copyWord(char sentenceIn[ ], char word[ ], int b, int e);
int DetermineRule(char word[ ]);
void ApplyRule1(char newWord[ ], char word[ ]);
void ApplyRule2(char newWord[ ], char word[ ]);
void ApplyRule3(char newWord[ ], char word[ ]);
void CreateSentenceOut(char sentenceOut[], char newWord[]);

int main()
{
      char sentenceIn[MAX]="";
      char word[MAX]="";
      char newWord[MAX]="";
      char sentenceOut[MAX*3]="";
      int trash=0,
            i=0,
            nextblank = 0,
            nextnonblank = 0,
            choice = 0,
            c = 0;

      FILE*outp;
      outp = fopen("out.txt","w");

      DisplayRules( );

    printf ("\nEnter 1 to Quit anything else to continue > ");
      choice = Menu();

      while(choice != 1)
      {      
            strcpy(sentenceIn,"");

            printf("Enter a sentence: ");

            scanf("%c",&trash);
            
            gets(sentenceIn);

            printf("\n%s\n", sentenceIn);

            fprintf(outp, "%s", sentenceIn);

            i = 0;

            while(sentenceIn[i] !='\0')
            {

                  nextnonblank=NextNonBlank(sentenceIn, i);
                  nextblank=NextBlank(sentenceIn,nextnonblank);
                  strcpy(word,"");
                  strncat(word, &sentenceIn[nextnonblank],nextblank - nextnonblank);


                  printf("check word:%s\t", word);//<<This is where I have stopped so far and the printf shows something is wrong.

            }



            printf ("\nEnter 1 to Quit anything else to continue > ");
            choice = Menu();
      }
      printf("\nGOODBYE!\n\n");

      fclose(outp);

      return 0;
}

int Menu()
{
      int select;
      scanf("%d", &select);
      return(select);
}

void DisplayRules()
{
      printf("Hello and thank you for using my language conversion program.\n");
      printf("Before we continue we need to provide some rules. First when\n");
      printf("being asked to type in your sentence, please refrane from using\n");
      printf("from using such symbols as: !@#$ and etc.\n");
      printf("If you follow that rule your sentence will run flawlessly! Have\n");
      printf("fun and enjoy the wonders of what piglatin has brought to the world!\n\n\n\n");
}

int DetermineRule(char word[])
{

      char letters[3];

      letters[0] = word[0];
      letters[1] = word[1];

      letters[0] = toupper(letters[0]);
      letters[1] = toupper(letters[1]);

      if((letters[0]=='A')||(letters[0]=='E'))
            return 2;

      else if((letters[0]=='I')||(letters[0]=='O'))
            return 2;

      else if((letters[0]=='U')||(letters[0]=='Y'))
            return 2;

      else if(strncmp, (letters, "TH", 2)==0)
            return 1;

      else if(strncmp, (letters, "CH", 2)==0)
            return 1;

      else if(strncmp, (letters, "SH", 2)==0)
            return 1;

      else if(strncmp, (letters, "PH", 2)==0)
            return 1;

      else if(strncmp, (letters, "WH", 2)==0)
            return 1;

      else if(strncmp, (letters, "QU", 2)==0)
            return 1;


      else return 3;

}


int NextNonBlank(char sentenceIn[ ], int c)
{
      while(sentenceIn[c]==' ')
      {c++;}
      return c;

}


int NextBlank(char sentenceIn[ ], int c)
{
      while(sentenceIn[c] != ' ')
      {
            if(sentenceIn[c]=='\0')
            {return c;}
            c++;
      }
}
---------------------------------------------------------------

What the last step is doing is it is trying to make a string called array. When the user enters a sentence, the program is supposed to take the sentence and look for the first nonspace(meaning the first letter of the word) take its place value into consideration, then another function (using a while loops starting at the value of where the first letter was) finds the next blank. This then finds how long the word is. This is as far as I've gotten and I want to print my words but something seems to be wrong.


0
 
Infinity08Commented:
On first sight : your NextBlank() function doesn't return c at the end.
0
 
Redevo7Author Commented:
Not understanding what you mean. Shouldn't the function return something since it is of int return type?
0
 
Redevo7Author Commented:
I guess the whole strings concept isn't 100% with my right now so this is why the program is kinda sketchy at the moment.
0
 
Redevo7Author Commented:
Im trying to work step by step but once I get to:

printf("check word:%s\t", word);//<<This is where I have stopped so far and the printf shows something is wrong.

----------------------

I just get the world hello printed an infinite number of times. I can't seem to find the error in my while loop.
0
 
Infinity08Commented:
>> Shouldn't the function return something since it is of int return type?
indeed, but it doesn't at the moment.

>> I guess the whole strings concept isn't 100% with my right now so this is why the program is kinda sketchy at the moment.
The way you're doing it now is indeed a bit too complicated, but you've almost got it working, so maybe it's best to finish it your way first. Once that works, we'll show you how you could have done certain things easier/better.

If that's ok with you ...
0
 
Infinity08Commented:
>> I just get the world hello printed an infinite number of times. I can't seem to find the error in my while loop.
That's because i is always 0 at the start of the while loop ... you never change i !
0
 
Redevo7Author Commented:
The only problem is the homework specifically states that you need to use a certain number of 1. functions; and 2. functions must do certain commands.


From what I understand that there is a much easier way to do it all but I'm following the prof. requirements so far.

I am writing the syntax so that I can work step by step. I'm printing my results slowly thru the program and thus i know where the program is not succeeding and when I can continue to the next part.

So far I am stuck at my last response(Refer to above comment)

I know reading C is def. a tedius task but Im trying to make this easy to read.
0
 
Infinity08Commented:
>> From what I understand that there is a much easier way to do it all but I'm following the prof. requirements so far.
OK.

>> I am writing the syntax so that I can work step by step. I'm printing my results slowly thru the program and thus i know where the program is not succeeding and when I can continue to the next part.
That is a very good approach to a task like this ... or any task for that matter.

>> So far I am stuck at my last response(Refer to above comment)
See my last post

>> I know reading C is def. a tedius task but Im trying to make this easy to read.
You're doing fine so far :)
0
 
Redevo7Author Commented:
>>That's because i is always 0 at the start of the while loop ... you never change i !

AHhah. Wow I forgot about the end incrementer. I added "i = nextblank;" at the end but now I need to provide a space after the word and NULL(\0) after each word.

Maybe thats further ahead I will continue. BRB!

Thanks Again!
0
 
Redevo7Author Commented:
Alright here is a somewhat complete program:

-----------------------------------------------------

#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define MAX 80


void DisplayRules( );
int Menu();
int NextNonBlank(char sentenceIn[ ], int count);
int NextBlank(char sentenceIn[ ], int count);
//void copyWord(char sentenceIn[ ], char word[ ], int b, int e);
int DetermineRule(char word[ ]);
void ApplyRule1(char newWord[ ], char word[ ]);
void ApplyRule2(char newWord[ ], char word[ ]);
void ApplyRule3(char newWord[ ], char word[ ]);
void CreateSentenceOut(char sentenceOut[], char newWord[]);
void PrintSentenceOut(char sentenceOut[]);

int main()
{
      char sentenceIn[MAX]="";
      char word[MAX]="";
      char newWord[MAX]="";
      char sentenceOut[MAX*3]="";
      int trash=0,
            i=0,
            nextblank = 0,
            nextnonblank = 0,
            choice = 0,
            c = 0,
            size=0,
            rule=0;

      FILE*outp;
      outp = fopen("out.txt","w");

      DisplayRules( );

    printf ("\nEnter 1 to Quit anything else to continue > ");
      choice = Menu();

      while(choice != 1)
      {      
            strcpy(sentenceIn,"");

            printf("Enter a sentence: ");

            scanf("%c",&trash);
            
            gets(sentenceIn);

            fprintf(outp, "%s", sentenceIn);

            i = 0;

            while(sentenceIn[i] != '\0')
            {
                  strcpy(word,"");

                  nextnonblank=NextNonBlank(sentenceIn, i);

                  nextblank=NextBlank(sentenceIn,nextnonblank);

                  size = nextnonblank-nextblank;

                  strncat(word, &sentenceIn[nextnonblank],size);

                  //printf("check word: %s\n", word);

                  rule=DetermineRule(word);

                  if(rule==1)
                  {ApplyRule1(word, newWord);}

                  else if(rule==2)
                  {ApplyRule2(word, newWord);}

                  else if(rule==3)
                  {ApplyRule3(word, newWord);}

                  //printf("applied rule is: %d\n", rule);

                  CreateSentenceOut(sentenceOut, newWord, size);

                  PrintSentenceOut(sentenceOut);

                  i = nextblank;}

            printf ("\nEnter 1 to Quit anything else to continue > ");
            choice = Menu();
      }
      printf("\nGOODBYE!\n\n");

      fclose(outp);

      return 0;
}

int Menu()
{
      int select;
      scanf("%d", &select);
      return(select);
}

void DisplayRules()
{
      printf("Hello and thank you for using my language conversion program.\n");
      printf("Before we continue we need to provide some rules. First when\n");
      printf("being asked to type in your sentence, please refrane from using\n");
      printf("from using such symbols as: !@#$ and etc.\n");
      printf("If you follow that rule your sentence will run flawlessly! Have\n");
      printf("fun and enjoy the wonders of what piglatin has brought to the world!\n\n\n\n");
}

int DetermineRule(char word[])
{

      char letters[3];

      letters[0] = word[0];
      letters[1] = word[1];

      letters[0] = toupper(letters[0]);
      letters[1] = toupper(letters[1]);

      if((letters[0]=='A')||(letters[0]=='E'))
            return 2;

      else if((letters[0]=='I')||(letters[0]=='O'))
            return 2;

      else if((letters[0]=='U')||(letters[0]=='Y'))
            return 2;

      if(strncmp(letters, "TH", 2)==0)
            return 1;

      if(strncmp(letters, "CH", 2)==0)
            return 1;

      if(strncmp(letters, "SH", 2)==0)
            return 1;

      if(strncmp(letters, "PH", 2)==0)
            return 1;

      if(strncmp(letters, "WH", 2)==0)
            return 1;

      if(strncmp(letters, "QU", 2)==0)
            return 1;

      else return 3;

}


int NextNonBlank(char sentenceIn[ ], int c)
{
      while(sentenceIn[c]==' ')
      {c++;}
      return c;

}


int NextBlank(char sentenceIn[ ], int nb)
{
      while(sentenceIn[nb] != ' ')
      {
            if(sentenceIn[nb]=='\0')
            {return nb;}
            nb++;
      }
      return nb;
}

void ApplyRule1(char newWord[ ], char word[ ])
{
      strcpy(newWord, &word[2]);
      strncat(newWord, word, 2);
      strcat(newWord, "AY");
}


void ApplyRule2(char newWord[ ], char word[ ])
{
      strcpy(newWord, &word[2]);
      strncat(newWord, word, 2);
      strcat(newWord, "AY");

}

void ApplyRule3(char newWord[ ], char word[ ])
{
      strcpy(newWord, &word[2]);
      strncat(newWord, word, 2);
      strcat(newWord, "AY");

}

void CreateSentenceOut(char sentenceOut[], char newWord[], int size)
{
      FILE *outp;
      int i=0;

      while(i>0)
      {
            strncat(newWord, "AY", size - 1)==sentenceOut;
            fprintf(outp, "%s", sentenceOut);
      i=size+1;
      }
}



void PrintSentenceOut(char sentenceOut[])
{
      printf("Your new word is now:\n\n %s", sentenceOut);
}

-----------------------------------------------------------------

Issues are as followed:

1. My sentences aren't seperated completely and placed into "word" declaration.
2. When I try to change the word nothing happens and nothing is entered into newWord.
3. I now need to have an outfile with the new sentence converted to the final version, and all words must be printed out together
    In my code for some reason I get a loop that gives the first word and does nothing, then the second word and does nothing!

I guess as of right now my int main function is my main importance right now.
0
 
Redevo7Author Commented:
anyone?
0
 
Redevo7Author Commented:
nobody?
0
 
Redevo7Author Commented:
=(
0
 
Infinity08Commented:
There's a few things wrong with this function :

void CreateSentenceOut(char sentenceOut[], char newWord[], int size)
{
     FILE *outp;
     int i=0;

     while(i>0)
     {
          strncat(newWord, "AY", size - 1)==sentenceOut;
          fprintf(outp, "%s", sentenceOut);
     i=size+1;
     }
}

1) changes to the parameters won't be visible in main
2) you always assign i = size + 1 at the end of the while loop ... this can create an endless loop.
3) comparing the result of strncat and sentenceOut is almost certainly NOT what you want ... what are you trying to do ?
0
 
PaulCaswellCommented:
Further:

1. Prototype for CreateSentenceOut should read:

void CreateSentenceOut(char sentenceOut[], char newWord[], int size);

2. What did you mean by this:

strncat(newWord, "AY", size - 1)==sentenceOut;

I mean the ==.... Looks like a typo.

3. Also, in CreateSentenceOut, you are using outp without initialising it. That wont work.

4. Finally:

     int i=0;

     while(i>0)

Means that the contents of the loop will never be executed because if i = 0 to start with, i will not be > 0.

Paul
0
 
Redevo7Author Commented:
Let me elaborate on my ApplyRule1, ApplyRule2, and ApplyRule3 function definitions.

If the "Determinerule" finds that the starts with th, wh, sh and etc, if then it falls under rule 1
   -Then the function ApplyRule 1 is used.
   -The function ApplyRule1 is supposed to take the first two letters, put it at the end of the word, concatinate, add AY to the end and place it onto newWord.

If the "Determinerule" finds that the word starts with a,e,i,o,u then rule 2 applies.
   -The function ApplyRule2 is supposed to just place AY at then of the word and then place the word onto newWord

Else for "determinerule" the function uses "ApplyRule3"
  -This takes the first letter of the word places it at the end, concatinate, add AY to the end and then add it to newWord

The tricky part I'm seeing is udnerstanding the string function. The professor gave us this function to help us understand it a little bit better but not sure as to it is exactly doing:

void ApplyRule1(char newWord[ ], char word[ ])
     
     strcpy(newWord, &word[2]);
     strncat(newWord, word, 2);
     strcat(newWord, "AY");

  -Can someone elaborate on the process that is going on here. I can probably figure the other functions out but I just need to figure out how the string is working
   here.

--------------------------

Then someone stated that I need to I need to initialize fileoutp? How do I do that, isn't already done in the main function or does that not apply? As you can tell my programing skills aren't very solid yet but I am getting there for sure.

Again thanks for the responses!
0
 
PaulCaswellCommented:
Hi Redevo7,

Say you have the word 'latin'

     strcpy(newWord, &word[2]);
//newWord contains "tin".
     strncat(newWord, word, 2);
//newWord contains "tinla".
     strcat(newWord, "AY");
//newWord contains "tinlaAY".

This is an old fake language called 'Pig Latin'. You should find plenty of descriptions on the internet.

>>Then someone stated that I need to I need to initialize fileoutp...
If you declare a local variable with the same name is one in another function, it doesnt share its value, it is a new variable. If you need a variable to be shared between functions you must either pass it as a parameter or us a 'global' variable. Look up the word 'global' in your manual for an explanation.

>>As you can tell my programing skills aren't very solid yet but I am getting there for sure.
You're doing fine! Dont worry! Just practice and learn.

Paul
0
 
Infinity08Commented:
Pheeew ... just re-read my last reply, and it's really not very clear lol ... ignore it, and read Paul's reply instead heh.

>> Can someone elaborate on the process that is going on here. I can probably figure the other functions out but I just need to figure out how the string is working here

ok : the ApplyRule1() function takes two string parameters : newWord which will contain the pig-latin word after the function, and word which contains the original normal word :

      void ApplyRule1(char newWord[ ], char word[ ])

The first thing to do is to drop the first two characters from the word, by copying word into newWord starting from the third character :
     
           strcpy(newWord, &word[2]);

Then the first two characters need to be attached to the end :

           strncat(newWord, word, 2);

And finally, the string "AY" needs to be added at the end :

           strcat(newWord, "AY");


>> Then someone stated that I need to I need to initialize fileoutp? How do I do that
check out fopen() as you did in main()

>> , isn't already done in the main function or does that not apply?
outp is a local variable to main(), and is not visible in the other functions ... either :

1) make outp a global variable
2) pass outp to the function as a parameter
3) close the file in main(), and open it in the function
0
 
Redevo7Author Commented:
>> strcpy(newWord, &word[2]);
>>//newWord contains "tin".
>>     strncat(newWord, word, 2);
>>//newWord contains "tinla".
>>     strcat(newWord, "AY");
>>//newWord contains "tinlaAY".

So what I am seeing is that we start with the word: latin

strcpy(newWord, &word[2]); copies the values within the string constant up to string[2] (for 0,1, and 2 locations) into newWord

so originally newWord was just equal to "\o"

now newWord is equal to "tin". We were taught that strcpy does not add the null character at the end, which is ok for this portion of the program.

Then strncat(newWord, word, 2); copies n number of characters from "word" and adds it to the end correct of newWord? But how does it know where the end is?

Does strcpy actually add a null character and strncat looks for it to replace it?

Then strcat(newWord, "AY"); adds AY to the end of the newWord and adds a null character correct?




This is where my program requirements get tricky. The purpose of the program is that it will actually take a whole sentence entered by the user and what happens is this:

        1. The program takes the sentence and looks for which the location the beginning of the word starts and where the word ends
        2. After the program determines the length of the word, it passes those locations which have specific values, i.e. if the sentence were hello there  the first
            word is located in 0,1,2,3,4.
        3. After the word is placed onto "word" it is then analyzed using the DetermineRule function. Here porgram looks at first letters, makes them uppercase and
           then conditions are set and rules are returned back to the int main. So "hello" is a 3 type condition rule
        4.  Use the value of returned "rule" and do proper manipulations of the word, like described above.--hello==ellohAY
        5. My main problem now is how do I output(write) this output out to a file and then print the final results onto the screen. Here is a sample output given in
            the assignment:
                         
               Input: to COME TO THE aid OF their COUNTRY

               Translation: otAY OMECAY OTAY ETHAY aidAY OFAY eirthAY OUNTRYCAY

             dont mind the example as the whole this is "Now IS the TIME FOR ALL Good PROGRAMMERS to COME TO THE aid OF their COUNTRY"
             Ill say this once, programming is no easy task. It is definately a difficult thing to learn especially when NEVER being exposed to it. Next semester will be  
             engineering problems using matlab so it will only get tougher!


Anyways Ill try to finish the program and adjust my conversion functions and thanks for the help everyone!


0
 
Redevo7Author Commented:
Ok for some reason when I try to test a print to see what my word was converted to I just get AY

 my third apply functions look like this:

void ApplyRule3(char newWord[ ], char word[ ])
{
      strcpy(newWord, &word[1]);
      strncat(newWord, word, 0);
      strcat(newWord, "AY ");
      printf("newWord=%s\n\n", newWord);

}

When i compile...execute it just prints out "newWord=AY" What am I missing here?
0
 
Redevo7Author Commented:
Nevermind I figured out that my function should read:

void ApplyRule3(char word[ ]), char newWord[ ])


Im glad i figured that out on my own. Alright it's slowly catching on!!!!

brb.
0
 
uniquesCommented:
        //Again we need to clear out strings before we can attempt to change another sentence.
          strcpy(word,"");
          strcpy(newWord,"");
----

word and newWord are used multiple times in a sentence. Hence they should be cleared out after a word is processed, not after the complete sentence. Move these statements to the end of while(sentenceIn[i] != '\0') loop

while(sentenceIn[i] != '\0')
{
<everything else>
strcpy(word,"");
strcpy(newWord,"");
}
0
 
Redevo7Author Commented:
Thanks everyone for helping. I really needed help understanding strings and I feel I have a solid foundation on it.

Redevo7
0
 
PaulCaswellCommented:
Redevo7,

Strings are tough to get your head around! You've done well!

Now you are a short step from pointers and they are probably the most complex construct to understand. You'll probably do structures next. They are easier once you have strings.

REMEMBER: "Strings are always one byte longer than their length!" :-)

That one causes more bugs than any other in my opinion.

Good Luck!

Paul
0
 
Redevo7Author Commented:
Definately an interesting subject and it sure does beat all my other classes but I feel I haven't even touched the surface about what programming is all about. Im a mech. engineering major and next class is all about running serious engineering problems using MATLAB so we will have to see what thats all about.

Actually next assignment is almost like my second project but instead we are using Structures.

My main problem right now is remembering loops and arrays. Its a little fuzzy but I have a good grip on it just need more practice.

Hopefully I will find some interesting topics onthese to practice.

Thanks again everyone!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 18
  • 7
  • 4
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now