void alternate(char wordWord[][MAX],char wordVar[],int word[],int i,int j, int k, int l)
{
  char ang[4],si[3],ni[3],ay[3],sa[3],kay[4];
  int X,Y,Z1,Z2;
  strcpy(ang,"ang");
  strcpy(si,"si");
  strcpy(ni,"ni");
  strcpy(ay,"ay");
  strcpy(sa,"sa");
  strcpy(kay,"kay");
  tokenize(wordWord,wordVar,word,i,j,k,l);
  if(wordWord[j][k] == ang[4] || wordWord[j][k] == si[3])
    X = wordWord[j][k]; 
  else if(wordWord[j][k] == ni[3])
    Z1 = wordWord[j][k];
  else if(wordWord[j][k] == ay[3])
    Y= wordWord[j][k];
  else if(wordWord[j][k] == sa[3] || wordWord[j][k] == kay[4])
    Z2 = wordWord[j][k];
  printf("%c %c %c %c %c %c %c \n",ang[4],si[3],ni[3],ay[3],sa[3],kay[4]);
  printf("%d %d %d %d\n",i,j,k,l); 
  printf("Alternation 1: %c %c %c %c\n",Y,Z1,Z2,X);
  printf("Alternation 2: %c %c %c %C\n",Y,X,Z1,Z1);
  printf("Alternation 3: %c %c %c %c\n",Z2,Y,X,Z1);
}

is their something wrong with this? Every time I run it, it compiles but it does not get updated. if I delete something it still displays the previous printf. for example I delete the printf below alternation 1. what will happen is it will still display alternation 2 every time I run it. :confused:

You have segmentation faults all over the place. That may or may not be your problem, but fix them, then try again. For example, ang[] has length 4, so valid indexes are 0 through 3. Line 12 uses an index of 4. Unless that's on purpose, change it. Ditto line 20. Those indexes are all past the array boundaries.

by the way here is the whole code.

#include<stdio.h>
#include<stdlib.h>
#define MAX 30

void tokenize(char wordWord[][MAX], char wordVar[],int word[],int i,int j,int k,int l)
{
  printf("Input Sentence: ");
  gets(wordVar);
  do
  {
    if(wordVar[i]==' '|| wordVar[i]==','||wordVar[i]=='.'||wordVar[i]==';')
      {
        i++;
        j++;
        word[l]=k;
        k=0;
        printf("l=%d word[l] = %d\n",l,word[l]);
        l++;
      }
    else
      {
        k=l;
        wordWord[j][k]=wordVar[i];
        printf("j=%d k=%d word is = %c\n",j,k,wordWord[j][k]);
        i++;
        k++;
      }   
  }while(j<strlen(wordVar) && i<strlen(wordVar) || k>strlen(wordVar)); 
}

void alternate(char wordWord[][MAX],char wordVar[],int word[],int i,int j, int k, int l)
{
  char ang[4],si[3],ni[3],ay[3],sa[3],kay[4];
  int X,Y,Z1,Z2;
  strcpy(ang,"ang");
  strcpy(si,"si");
  strcpy(ni,"ni");
  strcpy(ay,"ay");
  strcpy(sa,"sa");
  strcpy(kay,"kay");
  tokenize(wordWord,wordVar,word,i,j,k,l);
  if(wordWord[j][k] == ang[4] || wordWord[j][k] == si[3])
    X = wordWord[j][k]; 
  else if(wordWord[j][k] == ni[3])
    Z1 = wordWord[j][k];
  else if(wordWord[j][k] == ay[3])
    Y= wordWord[j][k];
  else if(wordWord[j][k] == sa[3] || wordWord[j][k] == kay[4])
    Z2 = wordWord[j][k];
  printf("%c %c %c %c %c %c %c \n",ang[4],si[3],ni[3],ay[3],sa[3],kay[4]);
  printf("%d %d %d %d\n",i,j,k,l); 
  printf("Alternation 1: %c %c %c %c\n",Y,Z1,Z2,X);
  printf("Alternation 2: %c %c %c %C\n",Y,X,Z1,Z1);
  printf("Alternation 3: %c %c %c %c\n",Z2,Y,X,Z1);
}

int main()
{
  int i=0,j=0,k=0,l=0;
  int word[MAX];
  char menu,wordWord[MAX][MAX],wordVar[MAX];
  printf("[a] Add word \n[b] Add Co-occuring word \n[c] Delete word \n[d] Delete Co-occuring word \n[e] View Words \n[f] Search word \n[g] Import \n[h] Export \n[i] Segment sentences \n[j] Tokenize \n[k] Alternate \n[l] Translate \n[m] Exit \n");
  printf("Input letter of choice: ");
  scanf("%c",&menu);
  switch(menu)
  {
    case 'a' : break;
    case 'b' : break;
    case 'c' : break;
    case 'd' : break;
    case 'e' : break;
    case 'f' : break;
    case 'g' : break;
    case 'h' : break;
    case 'i' : break;
    case 'j' : {gets(wordVar);
               tokenize(wordWord,wordVar,word,i,j,k,l);}break;
    case 'k' :{gets(wordVar);
               alternate(wordWord,wordVar,word,i,j,k,l);}break;
    case 'l' : break;
    case 'm' : break;
   }
   system("pause");
  return 0;
}

You have segmentation faults all over the place. That may or may not be your problem, but fix them, then try again. For example, ang[] has length 4, so valid indexes are 0 through 3. Line 12 uses an index of 4. Unless that's on purpose, change it. Ditto line 20. Those indexes are all past the array boundaries.

So.. you are trying to say is that if I should use the value [3] on my printf to show the value of ang?

It appears that ang[] is a string, so if you want to display "ang", you do this...

printf("%s", ang); // note that it's "%s", not "%c", and there are no brackets

If you want to print a single character within that array, for example the 'g' in ang[], so this...

printf("%c", ang[2]); // note that it's "%c", not "%s", and there are brackets.  The index must be LESS THAN 4

This will "print" the NULL terminator. "Print" is in quotes since the NULL terminator isn't printable.

printf("%c", ang[3]);

This is going to either seg fault or print something that has nothing to do with the ang[] array since it points PAST the ang[] array's boundaries.

printf("%c", ang[4]); // array size is 4, so index must be less than 4
commented: Very informative +1

oh thanks I already fixed it. seems the %c should be %s. thanks a lot.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.