Let's say you put your input in 'acBuffer[]'
:
int iCount = 0;
for (iCount = strlen(acBuffer); iCount => 0; iCount--)
{
printf("%s\n", acBuffer);
acBuffer[iCount] = '\0';
}
Or something like that.
ps. Don't forget to include string.h
Nick Evan
Not a Llama
10,112 posts since Oct 2006
Reputation Points: 4,142
Solved Threads: 403
read closer:
i said: acBuffer[iCount] = '\0';
you typed:
acbuffer[icount]='0';
your output was:
hello
hell0
hel00
he00
h000
0000
Nick Evan
Not a Llama
10,112 posts since Oct 2006
Reputation Points: 4,142
Solved Threads: 403
The latest version of the compiler can be downloaded from here:
http://www.borland.com/downloads/download_cbuilder.html
#include <stdio.h>
int main ()
{
int a, i;
for (a=5; a>0; a--)
{
for (i=a; i<5; i++)
{
printf("x" );
}
printf("y\n");
getchar () ;
}
Your prev code was full of non standard functions. Dont use functions like clrscr ( ) and dont use non standard headers like #include <conio.h>
~s.o.s~
Failure as a human
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 733
THe code which you have attempted, makes use of "scanf" for accepting string or char data which normally is not advised since it leaves the input stream dirty and which will cause behaviour which u had not expected.
Better use the technique which i have used while accepting char data and it will always work like a breeze.
Also you have used only one for loop to implement your logic which is not correct since you normally need one for controlling the number of chars to be printed and the second one to actually print characters.
Try somehting like this:
int main()
{
int i = 0, j = 0 ;
char buffer[BUFSIZ] = {'\0'} ;
printf ("Enter the string you want to display: ") ;
fgets (buffer, BUFSIZ, stdin) ;
if (buffer[ strlen (buffer) - 1 ] == '\n')
buffer[ strlen (buffer) - 1 ] = '\0' ;
for ( i = strlen (buffer) ; i > 0; --i)
{
for ( j = 0; j < i; ++j)
{
putchar (buffer [j]) ;
}
putchar ('\n') ;
}
return 0 ;
}
PS:: And by the way my name is not Painkilller, its ~s.o.s~ :D
~s.o.s~
Failure as a human
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 733
int main()
{
int i = 0, j = 0 ;
char buffer[BUFSIZ] = {'\0'} ;
printf ("Enter the string you want to display: ") ;
fgets (buffer, BUFSIZ, stdin) ;
for ( i = strlen (buffer) ; i > 0; --i)
{
buffer[i] = '\0';
printf("&s\n", buffer);
}
return 0 ;
}
works fine too, saves CPU-time :surprised
Nick Evan
Not a Llama
10,112 posts since Oct 2006
Reputation Points: 4,142
Solved Threads: 403
#1: Please stop bolding your messages. It isn't necessary.
#2: The code you posted (here with CODE tags, use them please) was:
#include <stdio.h>
#include <string.h>
main()
{
char acbuffer[50];
int icount=0;
clrsrc();
printf("Enter Any Word: ");
scanf("%s", &acbuffer);
strlen(acbuffer);
for (icount=strlen(acbuffer); icount>0; icount--)
{
printf("%s\n", acbuffer);
acbuffer[icount]='0';
}
getche();}
Asniek_e said your '0' should be '\0'. That's almost all you need to fix.
There's one more thing but I'll let you figure that one out.
#3) main() is an integer function, therefore it must be specified as
int main()
WaltP
Posting Sage w/ dash of thyme
10,492 posts since May 2006
Reputation Points: 3,348
Solved Threads: 943
works fine too, saves CPU-time
... by destroying the original string :mrgreen:
~s.o.s~
Failure as a human
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 733
by destroying the original string
true as hell, but he didn't say he wanted to keep it :mrgreen:
Nick Evan
Not a Llama
10,112 posts since Oct 2006
Reputation Points: 4,142
Solved Threads: 403
true as hell, but he didn't say he wanted to keep it
Joking aside, it is actually is a OO practice to pass a constant variable to a display function and normally display functions dont manipulate the data passes to it.
Its bad bad bad..... :D
~s.o.s~
Failure as a human
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 733