![]() |
| | #1 |
| Registered User Join Date: Nov 2007
Posts: 25
| I'm stuck in two exercises and need help. The first one is to write a code which prints out the ASCII-tabel. I have no clue on this question. The second one is to write a code which counts the characters used in a file. I can write a code which counts the number of characters in a row or in a text which is gotten from the terminal (e.x. via "getchar"). but I don't know how it would be with a file. Can someone plz help me with these two questions? tnx in advance. |
| sifeet is offline | |
| | #2 |
| Kernel hacker Join Date: Jul 2007 Location: Farncombe, Surrey, England
Posts: 15,686
| Homework policy If you post some code that shows that you are trying, we can help you along with some suitable hints and suggestions. Don't expect us to do the homework for you. -- Mats
__________________ Compilers can produce warnings - make the compiler programmers happy: Use them! Please don't PM me for help - and no, I don't do help over instant messengers. |
| matsp is offline | |
| | #3 |
| Registered User Join Date: Sep 2006
Posts: 3,148
| Check out Wikipedia or just google for ASCII. Basically, when you press a key, that key has an ASCII number assigned to it. The ASCII table is the list of the values that are agreed upon, for interpreting each key press. If you can count the char's in a row of text from the terminal, then you need to just re-direct your input to be from a file, instead. How is the C keyword FILE used? I don't feel like repeating what's in your book or class notes. Read up, and post your code to try these exercises. Then we can specifically help you out, without getting carpal tunnel syndrome. |
| Adak is offline | |
| | #4 |
| Kernel hacker Join Date: Jul 2007 Location: Farncombe, Surrey, England
Posts: 15,686
| [pedant mode]FILE is not a keyword in C. It is part of the ANSI library definitions, and it's usually a pointer to an anonymous struct [that is, we don't know the internal structure of a FILE struct][/pedant mode]. -- Mats
__________________ Compilers can produce warnings - make the compiler programmers happy: Use them! Please don't PM me for help - and no, I don't do help over instant messengers. |
| matsp is offline | |
| | #5 |
| Registered User Join Date: Nov 2007
Posts: 25
| Sorry, I didn't even think abt sending my code ! thoughtless done! Here is the code. I can't go any further. the only thing I've done here is to get the ascii numbers (in decimal form 0 to 127) I don't know how to define the variable "charac" for each characterin the tabel. Code: #include <stdio.h>
#include <stdbool.h>
int main()
{
int ascinr,i;
char charac;
printf("ASCII-Number Character\n======= =========\n");
for (i=0;1<127;i++){
ascinr=i;
pritf("%d%f\n" ,ascinr,charac);
}
return 0;
}
|
| sifeet is offline | |
| | #6 |
| Kernel hacker Join Date: Jul 2007 Location: Farncombe, Surrey, England
Posts: 15,686
| Code: printf("%d%f\n" ,ascinr,charac);
Of coruse, charac is also not set to anything, so it will print utter garbage. -- Mats
__________________ Compilers can produce warnings - make the compiler programmers happy: Use them! Please don't PM me for help - and no, I don't do help over instant messengers. |
| matsp is offline | |
| | #7 |
| and the hat of Jobseeking Join Date: Aug 2001 Location: The edge of the known universe
Posts: 21,681
| > for (i=0;1<127;i++) 1 (aka ONE) is always less than 127 i (aka eye) might eventually make it past 127. |
| Salem is offline | |
| | #8 | |
| abyss - deep C Join Date: Oct 2007
Posts: 46
| Quote:
Well, the %f in your printf statement says the compiler to expect a floating point value and you are giving a character. Go through your C book and identify what format specifier is to be used for characters. Also, you could look at what are escape sequences to know how to print using tabs. cheers maverix | |
| maverix is offline | |
| | #9 |
| abyss - deep C Join Date: Oct 2007
Posts: 46
| Well, the %f in your printf statement says the compiler to expect a floating point value and you are giving a character. Go through your C book and identify what format specifier is to be used for characters. Also, you could look at what are escape sequences to know how to print using tabs. cheers maverix |
| maverix is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Beginner: Linked List question | WeatherMan | C++ Programming | 2 | 04-03-2008 07:16 AM |
| Quick IF statement question (beginner) | jim.rattlehead | C Programming | 23 | 11-29-2007 06:51 AM |
| beginner question | Barrot | C++ Programming | 4 | 08-19-2005 02:17 PM |
| Question About External Files (Beginner) | jamez05 | C Programming | 0 | 08-11-2005 07:05 AM |
| Beginner on Win32 apps, lame question. | Templario | C Programming | 3 | 11-06-2002 08:39 PM |