Code:
#include <stdio.h>
#include <stdio.h>
#define BUF 250
#define WSIZE 250
int main(void)
{
char buffer[BUF];
char **rev;
char word[WSIZE];
int x,g,f;
fgets(buffer , BUF , stdin);/* take user input*/
for(x=0 , g=0 , f=0; buffer[x]!='\0' ; x++ , f++)
{
word[f]=buffer[x];
if(buffer[x]==' ')
{
word[f]='\0';
rev[g]=strdup(word);
f=0;
g++;
}
}
word[f]='\0';
rev[g]=strdup(word);
for(x=g ; x>=0 ;x--)
{
printf("%s",rev[x]);
}
return 0;
}
this code is not working at all
but i've replaced this char **rev; with char *rev[3];
int this code
Code:
#include <stdio.h>
#include <stdio.h>
#define BUF 250
#define WSIZE 250
int main(void)
{
char buffer[BUF];
char *rev[3];
char word[WSIZE];
int x,g,f;
fgets(buffer , BUF , stdin);/* take user input*/
for(x=0 , g=0 , f=0; buffer[x]!='\0' ; x++ , f++)
{
word[f]=buffer[x];
if(buffer[x]==' ')
{
word[f]='\0';
rev[g]=strdup(word);
f=0;
g++;
}
}
word[f]='\0';
rev[g]=strdup(word);
for(x=g ; x>=0 ;x--)
{
printf("%s",rev[x]);
}
return 0;
}
and it works but i don't want to do this as i don't know how many words will be inputed!!
and take a look at this
Enter A String:
->Storm Man
(output)
sman
storm
first of all "sman" why did it copy the first letter in the string ?
second it prints new lines between the words???
i don't get this point also why did it do this ?
thanks in advance and i hope i asked the right question