Monday, July 27, 2009

C programmers! help!?

what is the code for this? I will ask the user to input a word(string) then it will be printed afterwards in reversed order..(eg: "program" will be "margorp")..using arrays pls...thanks!

C programmers! help!?
you just do a





string m_string;


scanf(%s,m_string);


char * arr = new char[m_string.length];


strcpy(arr,m_string);


for(int i=m_string.length;i%26gt;0;i--)


{


printf(%c,arr[i]);


}





I haven't compiled this code so you might need to do some adjustments, but this is the basic idea.
Reply:#include %26lt;stdio.h%26gt;


#include %26lt;conio.h%26gt;


#include %26lt;string.h%26gt;





void main()


{





char * m_string;


clrscr();


printf("\nEnter String to be Reversed: ");


scanf("%s", m_string);





char *arr=new char[m_string,strlen(m_string)];


strcpy(arr,m_string);





printf("Reversed String: ");





for(int i=strlen(m_string);i%26gt;=0;i--)


{


printf("%c", arr[i]);


}


getch();


}
Reply:Hi,





#include%26lt;stdio.h%26gt;


#include%26lt;conio.h%26gt;


#include%26lt;string.h%26gt;





void main()


{


char a[10];


int i;


clrscr();


gets(a);


for(i=strlen(a);i%26gt;=0;i--)


printf("%c\n",a[i]);


getch();


}





It is for a string of maximum length 10;

survey

No comments:

Post a Comment