PDA

View Full Version : C Questions



DWk
01-23-2004, 02:13 AM
Ok...finally got everything working

Ok, what is %lf, %c, and %ld?

Help me fast pleaseeeeeee :D :ph34r:

4play
01-23-2004, 02:53 AM
i have not done c in ages but htey just look like the names of variables to me.

how about showing us the code and we can tell ya.

DWk
01-23-2004, 03:10 AM
Hehe was hoping you would be here :D

Actually I found out what they were (after extensive researching :frusty: cough googling)

#ld = LONG Digit (or double.... probably digit)
#lf = LONG float (the L just tells you LONG..... you can use H and that would mean SHORT)
#c = character....

Actually, I'm making a basic C calculator. I'm almost done with it, but I do have some errors.... here's what I have now (by the way it's in spanish.... so you might not understand it much, but you would get the point)



void main()
{
  double primero;
  double segundo;
  char operador = 0;
  int cont;
  double respuesta;

  printf("La mera calcu de Leksi\n\n");

  printf("Instrucciones:\n\n");
  printf("Para sumar, utilice la forma x+y\n");
  printf("Para restar, utilice la forma x-y\n");
  printf("Para multiplicar, utilice la forma x*y\n");
  printf("Para dividir, utilice la forma x/y\n");
  printf("Para elevar, utilice la forma x^y\n\n");
 
  printf("Por favor ingrese la operacion a realizar\n");
  scanf("%lf %c %lf", &primero, &operador, &segundo);

  switch(operador)
  {
     case '+':
printf("Su respuesta es: ");
      printf("%lf", primero + segundo);
      break;

     case '-':
printf("Su respuesta es: ");
      printf("%lf", primero - segundo);
      break;

     case '*':
printf("Su respuesta es: ");
      printf("%lf", primero * segundo);
      break;

     case '/':
printf("Su respuesta es: ");
      if(segundo == 0)
         printf("\n\n\aSu denominador no puede ser CERO\n");
        else
         printf("%lf", primero / segundo);
           break;

     case '^':
printf("Su respuesta es: ");
printf("%lf", pow (primero,segundo));
break;
 
     default:
      printf("\n\aSu operacion no es correcta");
  }
}

Here's where I'm stuck at. The calculator works perfectly. For example, if you try "a+1" it gives you the "Incorrect operation" error. However, if the second term is something else (such as 1+a), it would take the second as 0 and give you 1 as the answer. Any ideas? Thanks :)

DWk
01-23-2004, 03:22 AM
Ok, yea I just tried everything with something else as the second number (1+a, 1-a, 1*a, 1/a, 1^a) and every time the a is taken as a 0 (zero).

Could this be because of the default?

DWk
01-23-2004, 03:33 AM
Formatted output: printf description
The format string given to the `printf' function may contain both ordinary characters (which are simply printed out) and conversion characters (beginning with a percent symbol, %, these define how the value of an internal variable is to be converted into a character string for output).

Here is the syntax of a conversion specification:

  %{flags: - + space 0 #}{minimum field width}{.}{precision}{length modifier}{conversion character}

Flags: `-' means left-justify (default is right-justify), `+' means that a sign will always be used, ` ' prefix a space, `0' pad to the field width with zeroes, '#' specifies an alternate form (for details, see the manual!). Flags can be concatenated in any order, or left off altogether.
Minimum field width: the output field will be at least this wide, and wider if necessary.
'.' separates the field width from the precision.
Precision: its meaning depends on the type of object being printed:
Character: the maximum number of characters to be printed.
Integer: the minimum number of digits to be printed.
Floating point: the number of digits after the decimal point.
Exponential format: the number of significant digits.
Length modifer: `h' means short, or unsigned short; `l' means long or unsigned long; `L' means long double.
Conversion character: a single character specifying the type of object being printed, and the manner in which it will be printed, according to the following table:
Character Type    Result

  d,i    int    signed decimal integer
    o      int    unsigned octal (no leading zero)
  x, X    int    unsigned hex (no leading 0x or 0X)
    u      int    unsigned decimal integer
    c      int    single character
    s      char *  characters from a string
    f      double  floating point [-]dddd.pppp
  e, E    double  exponential [-]dddd.pppp e[=/-]xx
  g, G    double  floating is exponent less than -4, or >= precision
                  else exponential
    p      void *  pointer
    n      int *  the number of characters written so far by printf
                  is stored into the argument (i.e., not printed)
    %              print %


Got that from around :D

DWk
01-23-2004, 10:23 PM
Great - oh well.

Now I have to do a project. Either a text editor (such as notepad) or a game (Galaga). If you have any ideas on how to do this, please let me know. If you find any programs around, please let me know so I can get ideas from it. I'm lost and I have to send in a part of the program tonight. So I'm in a hurry :(

Thanks :D

DWk
01-24-2004, 03:33 AM
:frusty: bump

:ph34r:

shn
01-24-2004, 03:48 AM
http://www.bluemug.com/research/text.pdf

DWk
01-24-2004, 03:53 AM
Originally posted by shn@23 January 2004 - 20:48
http://www.bluemug.com/research/text.pdf
Cool, thanks for that. I'll see what I can do :)

DWk
01-24-2004, 02:46 PM
Bump :ph34r:

Any help on the game? The Galaga-type of game looks easier, although I have no idea how to make a cycle for the ship to move using gotoxy(x,y) :ph34r: