Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

programme problems

Status
Not open for further replies.

kati

Programmer
May 10, 2001
4
GB
Hell.
i am a very new user to programming and espacialy c and i have a problem on the programme i want to design the user must input two charecters i.e. a, f . then i want my programme to type the letters from a to f i.e abcdef but dont know which way to go about it ive tried using switch statment does any body know a better way to do it.


I THANK YOU KATI.
 
Probably the easiest way is to just increment the letter in a loop and terminate when it reaches the second letter. You could use something like this to get you started, then perhaps put an if statement or two in to select the highest and lowest letter. let me know how you get on ...

#include<stdio.h>

void main()
{
char finish,start;
printf(&quot;\nEnter the first letter > &quot;);
start = getchar();
fflush(stdin);
printf(&quot;\nEnter the second letter > &quot;);
finish = getchar();
while(start <= finish)
{
printf(&quot;%c&quot;,start);
start++;
}
}

 
thank you but i do not what the fflush(stdin) is for is it something like clearing the stdard input charecters ?? never been shown this thank you ..
 
hello i maneged to do the programme with anouthe while statement i.e


#include<stdio.h>

void main()
{
char ch_one,
ch_two;


printf(&quot;\nEnter the first letter > &quot;);
ch_one = getchar();

fflush(stdin);

printf(&quot;\nEnter the second letter > &quot;);
ch_two = getchar();




while (ch_one <= ch_two)
{
printf(&quot;%c&quot;,ch_one);
ch_one++;
}

while (ch_one >= ch_two)
{
printf(&quot;%c&quot;,ch_two);
ch_two++;
}
}



i thank you agan bye
 
Glad you got it sorted. I've always been told to put a fflush() in after a getchar statement to clear the buffer otherwise the last character entered would stay in the buffer and the next getchar would be ignored. I think thats right anyway.
 
thank you again Denstar its apreaciated so much .Kati
 
Note that the expression:

fflush(stdin);

is undefined. There is nothing in the C standard that says that fflush(stdin) will discard characters from the input buffer. fflush() is only defined for output streams.

Here's a portable way to do it:

void
disard_input_characters(void)
{
int c;
while ((c=getchar())!='\n' && c!=EOF)
; /* Empty Loop */
}

Using void as a return value for main() is also non-portable, use int main() instead.

Russ
bobbitts@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top