Jump to content

How do i read one character at a time in a character sequence?

- - - - -

  • Please log in to reply
7 replies to this topic

#1
893075006`

893075006`

    Newbie

  • Members
  • Pip
  • 4 posts
Could someone please help me with this question:
Attached File  Screen shot 2011-10-10 at 10.38.43 PM.png   112.58K   31 downloads
I understand how to do it after i am able to read one character at a time but its only this one part that i do not know how to do. I am not allowed to use strings and arrays. I am only allowed to use logical operations, conditional statements and loops so yeah... plz help cause this is really puzzling me.

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
All you need to do is read one character at a time, and have another variable to keep track of the "highest" letter found so far.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
893075006`

893075006`

    Newbie

  • Members
  • Pip
  • 4 posts
how do i read one character at a time though? cause doesnt scanf only read 1 character and then its done reading the input. I am not allowed to repeatedly press enter btw.

#4
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
If you use a char variable, it will only read one character at a time, even if you typed in more than one. Use a loop to grab the characters in sequence.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#5
893075006`

893075006`

    Newbie

  • Members
  • Pip
  • 4 posts
could you elaborate how to grab the characters in sequence. i found out that you use scanf("%c%c", &a, &b); a and b are variables. how would i keep grabbing characters though. could someone plz show me the format of the loop with the scanf inside?

#6
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
while (input != '\n')
{
scanf("%c", &input);
//do stuff
}
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#7
893075006`

893075006`

    Newbie

  • Members
  • Pip
  • 4 posts
wouldnt you have to keep inputing the character sequence though because it goes scanf you put something then it goes scan f again and you would have to put something again right?

---------- Post added at 07:41 PM ---------- Previous post was at 06:41 PM ----------

ok i figured this out but how do i make it print the first case of letter?

#8
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
Back up a step, how do you FIND the first case? You should have it in memory, and just need to print the value.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users