A
Anouar
The point was to make a program that gives you the possibilty to enter
a sentence and when you press "enter" it should ask a number for
example when i press 4
It should take the 4th word out of the sentence and print it
example sentence "hello i am Anouar"
the space after hello should not be a problem for the program so whe i
ask for the second word it should give "i" for an answer..
this is what i've got so far
can anybody help me?
------------------------------------------------------------
------------------------------------------------------------
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int woord, counter, pointer;
char *wijzer[1000];
char zin[1000];
int main(){
void zetinArray();
void printUit();
zetinArray();
printUit();
}
void zetinArray(){
printf("Enter a sentence:\n");
counter=0;
pointer =0;
zin[teller] = getchar();
while(zin[counter]!='\n'){
if(zin[counter]==' ' || zin[counter] == '\n'){
zin[counter] = '\0';
counter ++;
pointer++;
wijzer[pointer] = &zin[counter];
}else{
wijzer[pointer] = &zin[counter];
}
counter++;
zin[counter] = getchar();
}
}
void printUit(){
printf("%s\n",wijzer[0]);
printf("%s\n",wijzer[1]);
printf("%s\n",wijzer[2]);
printf("%s\n",wijzer[3]);
printf("Wich word do you want?\n");
scanf("%d",&woord);
printf("%s",wijzer[woord]);
}
a sentence and when you press "enter" it should ask a number for
example when i press 4
It should take the 4th word out of the sentence and print it
example sentence "hello i am Anouar"
the space after hello should not be a problem for the program so whe i
ask for the second word it should give "i" for an answer..
this is what i've got so far
can anybody help me?
------------------------------------------------------------
------------------------------------------------------------
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int woord, counter, pointer;
char *wijzer[1000];
char zin[1000];
int main(){
void zetinArray();
void printUit();
zetinArray();
printUit();
}
void zetinArray(){
printf("Enter a sentence:\n");
counter=0;
pointer =0;
zin[teller] = getchar();
while(zin[counter]!='\n'){
if(zin[counter]==' ' || zin[counter] == '\n'){
zin[counter] = '\0';
counter ++;
pointer++;
wijzer[pointer] = &zin[counter];
}else{
wijzer[pointer] = &zin[counter];
}
counter++;
zin[counter] = getchar();
}
}
void printUit(){
printf("%s\n",wijzer[0]);
printf("%s\n",wijzer[1]);
printf("%s\n",wijzer[2]);
printf("%s\n",wijzer[3]);
printf("Wich word do you want?\n");
scanf("%d",&woord);
printf("%s",wijzer[woord]);
}