A student that needs your help

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Oct 2006
Posts: 5
Reputation: Phazawhy is an unknown quantity at this point 
Solved Threads: 0
Phazawhy Phazawhy is offline Offline
Newbie Poster

A student that needs your help

 
0
  #1
Oct 11th, 2006
:!: Im need to create a program for my requirement that will output:


Enter Any Word: ____ -(i typed Hello)
Hello
Hell
Hel
He
H

i think that i should use for and strlen but i cant make strlen work. please help

Thanyou,
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,919
Reputation: niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute 
Solved Threads: 304
Moderator
Featured Poster
niek_e's Avatar
niek_e niek_e is offline Offline
Cenosillicaphobiac

Re: A student that needs your help

 
0
  #2
Oct 11th, 2006
Let's say you put your input in 'acBuffer[]'
:


  1.  
  2. int iCount = 0;
  3.  
  4. for (iCount = strlen(acBuffer); iCount => 0; iCount--)
  5. {
  6. printf("%s\n", acBuffer);
  7. acBuffer[iCount] = '\0';
  8. }


Or something like that.

cheers Niek

ps. Don't forget to include string.h
Last edited by niek_e; Oct 11th, 2006 at 10:33 am.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 5
Reputation: Phazawhy is an unknown quantity at this point 
Solved Threads: 0
Phazawhy Phazawhy is offline Offline
Newbie Poster

Re: A student that needs your help

 
0
  #3
Oct 11th, 2006
Originally Posted by niek_e View Post
Let's say you put your input in 'acBuffer[]'
:


  1.  
  2. int iCount = 0;
  3.  
  4. for (iCount = strlen(acBuffer); iCount => 0; iCount--)
  5. {
  6. printf("%s\n", acBuffer);
  7. acBuffer[iCount] = '\0'; <============it doesnt work
  8. }


Or something like that.

cheers Niek

ps. Don't forget to include string.h


(i forgot to mentioned that i need this on C)!!!!!



this is my prog so far:

#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'; <======= right here i think need to decreased my word some how ..
}
getche();}


Need to decrease any word. EX. Hello then i will be Hell, Hel, He and so on until i doenst have any letters on it then the prog is terminated.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 5
Reputation: Phazawhy is an unknown quantity at this point 
Solved Threads: 0
Phazawhy Phazawhy is offline Offline
Newbie Poster

Re: A student that needs your help

 
0
  #4
Oct 11th, 2006
by the way i need a new c language prog. do anyone know where i can find the latest turbo c language exe? pls help
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,919
Reputation: niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute 
Solved Threads: 304
Moderator
Featured Poster
niek_e's Avatar
niek_e niek_e is offline Offline
Cenosillicaphobiac

Re: A student that needs your help

 
0
  #5
Oct 11th, 2006
read closer:

i said: acBuffer[iCount] = '\0';

you typed:

acbuffer[icount]='0';

your output was:

hello
hell0
hel00
he00
h000
0000
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 5
Reputation: Phazawhy is an unknown quantity at this point 
Solved Threads: 0
Phazawhy Phazawhy is offline Offline
Newbie Poster

Re: A student that needs your help

 
0
  #6
Oct 11th, 2006
nieke can you tell me what version your turbo c and where did you i can find download that cause im using version 2.1 and stdio.h doesnt work here...

here is an ex of a prog that my teacher gave to us but it doesnt work in version 2.1

#include <stdio.h>
#include <conio.h)
voidmain(){
clrsrc();
int a, i;
for (a=5; a>0; a--)
{
for (i=a; i<5; i++)
printf("x" );
printf("y\n");
}
getche();}

thanks for your reply i really need this or i will fail my class..
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,628
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 468
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: A student that needs your help

 
0
  #7
Oct 11th, 2006
The latest version of the compiler can be downloaded from here:
http://www.borland.com/downloads/download_cbuilder.html

  1. #include <stdio.h>
  2. int main ()
  3. {
  4. int a, i;
  5. for (a=5; a>0; a--)
  6. {
  7. for (i=a; i<5; i++)
  8. {
  9. printf("x" );
  10. }
  11. printf("y\n");
  12. getchar () ;
  13. }

Your prev code was full of non standard functions. Dont use functions like clrscr ( ) and dont use non standard headers like #include <conio.h>
I don't accept change; I don't deserve to live.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 5
Reputation: Phazawhy is an unknown quantity at this point 
Solved Threads: 0
Phazawhy Phazawhy is offline Offline
Newbie Poster

Re: A student that needs your help

 
0
  #8
Oct 11th, 2006
Painkiller,
Im need to create a program for my requirement that will output:


Enter Any Word: ____ -(i typed Hello)

Hello
Hell
Hel
He
H

i think that i should use for and strlen but i cant make strlen work. please help

Thanyou, can you help me? this is my original post..
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,628
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 468
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: A student that needs your help

 
0
  #9
Oct 11th, 2006
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:
  1. int main()
  2. {
  3. int i = 0, j = 0 ;
  4. char buffer[BUFSIZ] = {'\0'} ;
  5. printf ("Enter the string you want to display: ") ;
  6. fgets (buffer, BUFSIZ, stdin) ;
  7. if (buffer[ strlen (buffer) - 1 ] == '\n')
  8. buffer[ strlen (buffer) - 1 ] = '\0' ;
  9.  
  10. for ( i = strlen (buffer) ; i > 0; --i)
  11. {
  12. for ( j = 0; j < i; ++j)
  13. {
  14. putchar (buffer [j]) ;
  15. }
  16. putchar ('\n') ;
  17. }
  18. return 0 ;
  19. }

PS:: And by the way my name is not Painkilller, its ~s.o.s~
Last edited by ~s.o.s~; Oct 11th, 2006 at 2:24 pm.
I don't accept change; I don't deserve to live.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,919
Reputation: niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute 
Solved Threads: 304
Moderator
Featured Poster
niek_e's Avatar
niek_e niek_e is offline Offline
Cenosillicaphobiac

Re: A student that needs your help

 
0
  #10
Oct 12th, 2006
  1. int main()
  2. {
  3. int i = 0, j = 0 ;
  4. char buffer[BUFSIZ] = {'\0'} ;
  5. printf ("Enter the string you want to display: ") ;
  6. fgets (buffer, BUFSIZ, stdin) ;
  7.  
  8. for ( i = strlen (buffer) ; i > 0; --i)
  9. {
  10. buffer[i] = '\0';
  11. printf("&s\n", buffer);
  12.  
  13. }
  14. return 0 ;
  15. }
works fine too, saves CPU-time :surprised


Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC