Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > C/C++
You last visited: Today at 15:57

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



[C] Verständnisproblem Formatzeichen

Discussion on [C] Verständnisproblem Formatzeichen within the C/C++ forum part of the Coders Den category.

Reply
 
Old   #1
 
elite*gold: 0
Join Date: Mar 2009
Posts: 61
Received Thanks: 1
[C] Verständnisproblem Formatzeichen

Hallo elitepvpers Community,

ich habe aktuell ein Verstädnnisproblem bei einem Code-Beispiel ich hoffe ihr könnt mir dabei weiterhelfen.

Hier der Code:

Code:
#include <stdio.h>

int main(void) {
   char response;

   printf("Denk Dir eine Nummer zwischen 1 und 100 aus.\n");
   printf("Das errate ich in 7 oder weniger Versuchen \n\n");
   do {
      int lo = 1, hi = 100;
      int guess;
      while (lo <= hi) {
         guess = (lo + hi) / 2;
         printf("Ist es %d ",guess);
         printf(" ((h)oeher/(n)iedriger/(j)a): ");
         fflush(stdout);
         scanf("%c%*c",&response);

         if (response == 'h')
            lo = guess + 1;
         else if (response == 'n')
            hi = guess - 1;
         else if (response != 'j')
            printf("Erraten ... :-)");
         else
            break;
      }
     
      if (lo > hi)
         printf("Du schummelst!\n");
      else
         printf("Deine Nummer lautet: %d\n",guess);
      printf("Noch ein Spiel (j)a/nein : ");
      fflush(stdout);
      scanf("%c%*c",&response);
   } while( response == 'j' );
   return 0;
}
Mein Problem:
Warum wird hier scanf("%c%*c",&response); verwendet?
Warum kann ich an dieser Stelle kein normales Formatzeichen für einen Char verwenden (also %c)?
Wieso wird hier %c%*c benutzt?
Was genau steckt dahinter?
In welchen Fällen findet das Anwendung?

MfG RappelzFrEaK
RappelzFrEaK is offline  
Old 11/25/2012, 12:58   #2
 
elite*gold: 0
Join Date: Jan 2011
Posts: 362
Received Thanks: 41
Habe den code gerade mit %c laufen lassen, kommt auf dasselbe hinaus :-)
Rullx3 is offline  
Old 11/25/2012, 14:25   #3
 
elite*gold: 0
Join Date: Mar 2009
Posts: 61
Received Thanks: 1
Bei mir nicht...lasse ich das Programm mit %c%*c laufen funktioniert alles, schreibe ich an den beiden stellen nur %c rein funktioniert es nicht mehr wie es soll.
Hab es mit Bloodshed Dev-C++ und Visual Studio ausprobiert beides mal wenn ich %c benutze und ich gebe zum Beispiel h ein gibt er mir aus Erraten fragt danach aber weiter.
RappelzFrEaK is offline  
Reply


Similar Threads Similar Threads
C++ Verständnisproblem :(
08/18/2010 - C/C++ - 7 Replies
Gelöst Hi, manchmal wenn ich durch source codes rumsurfe immer wieder folgendes Konstrukt was ich grad iwie net ganz kapiere Beispielhaft mal das #include <stdio.h> #include <dlfcn.h>



All times are GMT +1. The time now is 15:58.


Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2026 elitepvpers All Rights Reserved.