Help on writing program

This is a discussion on Help on writing program within the C Programming forums, part of the General Programming Boards category; I have some instrucions here to write a program and I have no clue where to start. here are the ...

  1. #1
    Registered User
    Join Date
    Feb 2005
    Posts
    76

    Help on writing program

    I have some instrucions here to write a program and I have no clue where to start.

    here are the instructions:

    Write a C Program to generate output given by a3q3.exe. You will need to use printf with format specifier %c to print ASCII values of 218,196,191, 179, 192 and 217.

    please look at the example.
    Attached Images Attached Images  

  2. #2
    Registered User
    Join Date
    Mar 2004
    Posts
    494
    Declare some int variables and assign the numeric values that you have, and then print them out using the %c specifier. Another solution which is easier i guess is to use putchar.
    When no one helps you out. Call google();

  3. #3
    Registered User
    Join Date
    Feb 2005
    Posts
    76
    Do you mean like this

    Code:
     #include <conio.h>
    #include <stdio.h>
    #define int   218,196,191, 179, 192,217;
    main(void){
         printf("");
      printf("");
        getche();
    }
    Last edited by robasc; 03-06-2005 at 04:35 PM.

  4. #4
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    University of Waterloo
    Posts
    1,903
    Umm. No.

    You've already been given the answer to this. Just use printf("%c",<value>); where <value> is the int value you want to print and voila, you're on your way.

  5. #5
    Registered User
    Join Date
    Feb 2005
    Posts
    76
    ok like this
    Code:
    #include <conio.h>
    #include <stdio.h>
    
    main(void){
         printf("%c,217");
      printf("");
        getche();
    }

  6. #6
    Registered User
    Join Date
    Mar 2004
    Posts
    494
    nope thats not a solution either, you have not declared a variable or intialized it with a value.

    to declare a variable you do something like this
    Code:
     int num1;
    to initialized the variable you do something like this,
    Code:
     num1 = 217;
    to print it out you do something like this.
    Code:
    printf("the ASCII value of 217 is%c \n", num1);
    When no one helps you out. Call google();

  7. #7
    Registered User
    Join Date
    Feb 2005
    Posts
    76
    when you run this code above it print an H. I thought that the value of 218 should look like
    an upside down L?

  8. #8
    Registered User
    Join Date
    Mar 2004
    Posts
    494
    it is an upside down L .

    my output for 218. is

    Code:
    The ascii value of 218 is: ┌.
    Press any key to continue
    When no one helps you out. Call google();

  9. #9
    Registered User
    Join Date
    Feb 2005
    Posts
    76
    isnt this assignment supposed to print some assigned ascii code to make the above example?

  10. #10
    Registered User
    Join Date
    Mar 2004
    Posts
    494
    You just use the numeric value of 218 to print the ascii code that looks like an upside down L. show the code where you getting H on your output, maybe you doing something wrong.
    When no one helps you out. Call google();

  11. #11
    Registered User
    Join Date
    Feb 2005
    Posts
    76
    ok this is the only way I could compile this to run it:

    Code:
    #include <conio.h>
    #include <stdio.h>
    
    main(void){
               int number1;
               number1 = 218;
           printf("the ASCII value of 218 is%c \n, num1");
        getche();
    }
    Notice on the printf statement I made a small change. My compiler would not compile it =, I keep getting compiler errors

    such as:

    Compiler: Default compiler
    Executing gcc.exe...
    gcc.exe "C:\Documents and Settings\dustin\My Documents\computer programming class\ass3,q3.c" -o "C:\Documents and Settings\dustin\My Documents\computer programming class\ass3,q3.exe" -I"C:\Dev-Cpp\include" -L"C:\Dev-Cpp\lib"
    C:\Documents and Settings\dustin\My Documents\computer programming class\ass3,q3.c: In function `main':
    C:\Documents and Settings\dustin\My Documents\computer programming class\ass3,q3.c:7: error: `num1' undeclared (first use in this function)
    C:\Documents and Settings\dustin\My Documents\computer programming class\ass3,q3.c:7: error: (Each undeclared identifier is reported only once
    C:\Documents and Settings\dustin\My Documents\computer programming class\ass3,q3.c:7: error: for each function it appears in.)

    Execution terminated

  12. #12
    Registered User
    Join Date
    Feb 2005
    Posts
    76
    My output reads: The ascII value of 217 isH

  13. #13
    Registered User
    Join Date
    Mar 2004
    Posts
    494
    notice your printf statement and notice the printf statement i posted as an example, you see the difference?
    When no one helps you out. Call google();

  14. #14
    Registered User
    Join Date
    Feb 2005
    Posts
    76
    I am sure that the problem lies in the printf statement;however,
    it will not compile the way you wrote it.

    Code:
    #include <conio.h>
    #include <stdio.h>
    
    main(void){
               int number1;
               number1 = 218;
          printf("the ASCII value of 217 is%c \n", num1);
        getche();
    }
    what else am I doing wrong?

  15. #15
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    You refer to num1 in your printf statement. You haven't defined num1. Define it, or change the variable that you're referring to.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Writing a program to make a calendar
    By Northstar in forum C Programming
    Replies: 17
    Last Post: 11-07-2007, 10:34 AM
  2. writing a calendar program help please!!!
    By Newbie2006 in forum C Programming
    Replies: 7
    Last Post: 11-20-2002, 06:36 PM
  3. Replies: 5
    Last Post: 11-19-2002, 08:36 PM
  4. Help with a file writing program
    By pritesh in forum C Programming
    Replies: 3
    Last Post: 11-11-2001, 12:56 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21