943,983 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 2175
  • C RSS
You are currently viewing page 1 of this multi-page discussion thread
Oct 11th, 2006
0

A student that needs your help

Expand Post »
:!: 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,
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Phazawhy is offline Offline
5 posts
since Oct 2006
Oct 11th, 2006
0

Re: A student that needs your help

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.


ps. Don't forget to include string.h
Last edited by Nick Evan; Apr 27th, 2011 at 7:03 am.
Moderator
Featured Poster
Reputation Points: 4142
Solved Threads: 394
Industrious Poster
Nick Evan is offline Offline
4,132 posts
since Oct 2006
Oct 11th, 2006
0

Re: A student that needs your help

Click to Expand / Collapse  Quote originally posted by niek_e ...
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:

  1. #include <stdio.h>
  2. #include <string.h>
  3. main(){
  4. char acbuffer[50];
  5. int icount=0;
  6. clrsrc();
  7. printf("Enter Any Word: ");
  8. scanf("%s", &acbuffer);
  9. strlen(acbuffer);
  10. for (icount=strlen(acbuffer); icount>0; icount--)
  11. {
  12. printf("%s\n", acbuffer);
  13. acbuffer[icount]='0'; <======= right here i think need to decreased my word some how ..
  14. }
  15. 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.
Last edited by Nick Evan; Apr 27th, 2011 at 7:03 am.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Phazawhy is offline Offline
5 posts
since Oct 2006
Oct 11th, 2006
0

Re: A student that needs your help

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Phazawhy is offline Offline
5 posts
since Oct 2006
Oct 11th, 2006
0

Re: A student that needs your help

read closer:

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

you typed:

acbuffer[icount]='0';

your output was:

hello
hell0
hel00
he00
h000
0000
Moderator
Featured Poster
Reputation Points: 4142
Solved Threads: 394
Industrious Poster
Nick Evan is offline Offline
4,132 posts
since Oct 2006
Oct 11th, 2006
0

Re: A student that needs your help

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

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

thanks for your reply i really need this or i will fail my class..
Last edited by Nick Evan; Apr 27th, 2011 at 7:03 am.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Phazawhy is offline Offline
5 posts
since Oct 2006
Oct 11th, 2006
0

Re: A student that needs your help

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>
Super Moderator
Featured Poster
Reputation Points: 3233
Solved Threads: 720
Failure as a human
~s.o.s~ is offline Offline
8,872 posts
since Jun 2006
Oct 11th, 2006
0

Re: A student that needs your help

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..
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Phazawhy is offline Offline
5 posts
since Oct 2006
Oct 11th, 2006
0

Re: A student that needs your help

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.
Super Moderator
Featured Poster
Reputation Points: 3233
Solved Threads: 720
Failure as a human
~s.o.s~ is offline Offline
8,872 posts
since Jun 2006
Oct 12th, 2006
0

Re: A student that needs your help

  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


Moderator
Featured Poster
Reputation Points: 4142
Solved Threads: 394
Industrious Poster
Nick Evan is offline Offline
4,132 posts
since Oct 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: writing a program
Next Thread in C Forum Timeline: compiling error





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC