Sunday, July 12, 2009

Help plz using c?

this program reverses the string entered by input from the user.





int main() {


char string[256];


int len;


fgets(file, 256-1, stdin);


len = (strlen(string) - 1);


printf("You entered %s \nlength %d:\n", file, len);


printf("Reverse string:");


for(; len %26gt;= 0; len--)


printf("%c",file[len]);


printf("\n");


}


i need to do this


You will read in a file supplied from the commandline (filename.ext,) and write/overwrite out a file which will be called (filename.ext.mng.)





This file will be essentially the same as the original file, but will have all characters on all lines the reverse of the original. For example:


The original file has:


Jack Spratt


could eat no fat.


His wife


could eat no lean.


The output file will look like:


ttartpS kcaJ


.taf on tae dluoc


efiw siH


.nael on tae dluoc

Help plz using c?
Take out the printf's ("You entered %s....." and "Reverse string...").





Take out the printf("\n"); at the end of the loop.





Then just do it from the command line:





myprog %26lt;filename.ext %26gt;filename.ext.mng
Reply:your reverse program dosen't seem to be working


here is a program that works:


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





void reverse( const char * const sPtr );





int main(){


char sentence[ 80 ];





printf( "Enter a line of text:\n" );


gets( sentence );





printf( "\nThe line printed backwards is:\n" );


reverse( sentence );


}





void reverse( const char * const sPtr ){


if( sPtr[ 0 ] == '\0' ){


return;


}


else{


reverse( %26amp;sPtr[ 1 ] );





putchar( sPtr[ 0 ] );


}


}

parts of a flower

No comments:

Post a Comment