• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

can someone point out what I am doing wrong in trying to use ASCII values in C?

Onceler

Golden Member
Code:
#include<stdio.h>
int main()
{
    FILE *fp;
fp=fopen("d:\\crypt.h", "w");

fprintf(fp, "char out[8];char cur[8];"
        "char con[255,255,255,255,255,255,255,255];/n"
        "if cur==con out==0,0,0,0,0,0,0,0;/n"
        "while(cur <= con) /n"
            "con=con-1/n"

            "if cur>=con out=out+1;");
         return 0;
}
I am trying to use the char array to store ASCII characters and to print them on the screen.
Thanks
 
Last edited:
Code:
 "char con[255,255,255,255,255,255,255,255];/n"
Wut? 😵

Did you mean:

Code:
 "char con[8]=[B]{[/B]255,255,255,255,255,255,255,255[B]}[/B];[B]\[/B]n"
If so, realize that you can only initialize an array this way. To change all the values to 0, for instance, you need a loop. (Or alternatively 8 separate statements in this case.)

Edit: Your ifs also need parentheses, and note the "\n", not "/n".
Edit2: Also, arrays are not initialized to anything in particular in C unless they're global. You should initialize all your arrays, either with a loop or as I did above.
 
Last edited:
Thank you.
Any ideas on how I could self automate this to generate it's own code with what it is now provided? A human couldn't possibly go through all those numbers ever.
 
I think you might want to get to the point where you can output valid C code before you take it to the next step. In addition to the stuff Ken mentioned there are quite a few other basic syntax errors.
 
If you're looking to write a program inside a string, see also [post=35865342]this really nice macro[/post] that somebody came up with in a recent post in this forum. That might also help your syntax highlighter make syntax errors more obvious.
 
Back
Top