Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Learner

Name: Anonymous 2011-09-06 7:39

Hey /prague/, beginner programmer here. I decided to make a program that prints every letter in an input in a different color. However, when I run it, it is all reproduced in blue. It there anyone who can identify the problem? This would be really helpful, education-wise.


#include <stdlib.h>
#include <stdio.h>
#include <windows.h>

void tc(int k) {SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), k);}

int main() {

    char r[60];
    char c;
    int i;
   
    int j = 0;
   
    for (i = 0; i < 60 && (c = getchar()) != '\n'; i++)
        r[i] = c;
   
    int l = i;
    i = 0;
   
    while (i < l) {
        j++;
        if (j = 16)
            j = 1;
        tc(j);
        putchar(r[i]);
        i++;
    }
   
    return 0;

}

Name: Anonymous 2011-09-06 7:57

if (j = 16)

Name: Anonymous 2011-09-06 8:02

>>1
stop using windows

Name: Anonymous 2011-09-06 8:07

>>2
Ah. Thank you, kind sir. Also, it works!

So my lesson today: Get my fucking comparison operators right.

Name: Anonymous 2011-09-06 8:12

#define EQ == /* Use for all code which requires testing for equality*/

Name: Anonymous 2011-09-06 8:59

>>2
Doesn't gcc issue a warni--
#include <windows.h>
Never mind.

Name: Anonymous 2011-09-06 10:05

Learning how to program in Windows isn't bad. Writing only Windows programs is bad. Learn to write for different operating systems concurrently!

Name: Anonymous 2011-09-06 10:10

DOUBLES

Name: Anonymous 2011-09-06 10:20

>>7
I only coded in VB6 in Windows and only started C (and 8 other languages) under GUN/Linux. I did code in Pascal under MS-DOS and actually liked it more than VB.

Don't change these.
Name: Email:
Entire Thread Thread List