Web lists-archives.com

Re: [Mingw-users] is this mingw error?




Hello there!

You overwrite the first letter every time. The last thing in there is EOF, I think. So that one is printed out. Increment "cur" somewhere. Increment is "cur++" or "++cur" or "cur +=1;" or "cur = cur + 1;".

I hope that helps.

I'm not very good in english, interpersonal stuff might sound a bit clumsy.

Regards
Foster


2017-02-27 5:24 GMT+01:00 Chan Oak <chanomail@xxxxxxxxx>:
here source code

#include <stdio.h>
#define MAX 100
char aaa[MAX];
int addstr(char a)
{
    static int cur = 0;
    if (cur > MAX)
        return 0;
    else
        aaa[cur] = a;
   
    return 1;
}
int main()
{
    char a;
    int i;
   
    while ((a = getchar()) != EOF)
    {
        addstr(a);
    }
    printf("%c", aaa[0]);
    printf("hello\n");
}

here is output

a
^Z
hello
the global array aaa[0] is modified yet it does not print aaa[0].
if I put printf inside function addstr to print aaa[0], it does print

is this compiler bug?

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
MinGW-users mailing list
MinGW-users@lists.sourceforge.net

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Also: mailto:mingw-users-request@lists.sourceforge.net?subject=unsubscribe

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
MinGW-users mailing list
MinGW-users@xxxxxxxxxxxxxxxxxxxxx

This list observes the Etiquette found at 
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Also: mailto:mingw-users-request@xxxxxxxxxxxxxxxxxxxxx?subject=unsubscribe