0

So to start this off, this is not the complete program. I am working on it and just ran into this problem. The first 3 times I call strcpy (in the first for-loop) it compiles without problem. However, the fourth through sixth times (in the second for-loop) I get the error message "too few arguments in function to call", even though the arguments are the same as in the first for-loop.

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <conio.h>
#include <string.h>

#define ESC 27

struct lag {
char namn[20];
int gjorda;
int inslappta;
int poang;
};

int main(void) {
    struct lag temp, serie[] = {
    { "Bryn\204s", 0, 0, 0 },
    { "Djurg\206rden", 0, 0, 0 },
    { "Fr\224lunda", 0, 0, 0 },
    { "F\204rjestad", 0, 0, 0 },
    { "HV 71", 0, 0, 0 },
    { "Link\224ping", 0, 0, 0 },
    { "Lule\206     ", 0, 0, 0 },
    { "MODO    ", 0, 0, 0 },
    { "R\224gle", 0, 0, 0 },
    { "Skellefte\206", 0, 0, 0 },
    { "S\224dert\204lje", 0, 0, 0 },
    { "Timr\206", 0, 0, 0 }
};
int i, j, k, hemma, borta;


srand((unsigned)time(NULL));

do {


    for (k = 0; k <= 10; k += 2)
    {
        hemma = rand() % 8;
        borta = rand() % 8;
        serie[k].gjorda = +hemma;
        serie[k].inslappta = +borta;
        serie[k + 1].gjorda = +borta;
        serie[k + 1].inslappta = +hemma;

        printf("%s - %s \t \t %d - %d \n", serie[k].namn, serie[k + 1].namn, hemma, borta);
    }

        if (hemma > borta)
            serie[i].poang = +3;

        else if (hemma == borta)
        {
            serie[i].poang = +1;
            serie[i + 1].poang = +1;
        }

        else if (hemma < borta)
            serie[i + 1].poang = +3;


        for (i= 0; i < 11; i++)
            for (j = i+1;j< 12; j++)
                if (serie[j].poang < serie[i].poang)
                {
                    temp.poang = serie[i].poang;
                    serie[i].poang = serie[j].poang;
                    serie[j].poang = temp.poang;

                    temp.gjorda = serie[i].gjorda;
                    serie[i].gjorda = serie[j].gjorda;
                    serie[j].gjorda = temp.gjorda;

                    temp.inslappta = serie[i].inslappta;
                    serie[i].inslappta = serie[j].inslappta;
                    serie[j].inslappta = temp.inslappta;

                    strcpy(temp.namn, serie[i].namn);     //These compile
                    strcpy(serie[i].namn, serie[j].namn);  
                    strcpy(serie[j].namn, temp.namn);      
                }



        for (i = 0; i < 11; i++)
            for (j = i + 1; j< 12; j++)
                if (serie[j].poang == serie[i].poang)
                    if ((serie[j].gjorda - serie[j].inslappta) < (serie[i].gjorda - serie[i].inslappta))
                    {
                        temp.poang = serie[i].poang;
                        serie[i].poang = serie[j].poang;
                        serie[j].poang = temp.poang;

                        temp.gjorda = serie[i].gjorda;
                        serie[i].gjorda = serie[j].gjorda;
                        serie[j].gjorda = temp.gjorda;

                        temp.inslappta = serie[i].inslappta;
                        serie[i].inslappta = serie[j].inslappta;
                        serie[j].inslappta = temp.inslappta;

                        strcpy_s(temp.namn, serie[i].namn);   //These don't
                        strcpy_s(serie[i].namn, serie[j].namn);
                        strcpy_s(serie[j].namn, temp.namn);
                    }





    } while (_getch() != ESC);
return 0;

}

  • 2
    The problem code uses `strcpy_s()`, which needs another argument. – ad absurdum Apr 05 '17 at 23:27
  • Oh right! I tried using that because my environment prompted me to. I got the warning "This function or variable may be unsafe. Consider using strcpy_s instead.", and it wouldn't compile unless I disabled some kind of deprication. Is that worth doing then? – Jakob Eklund Apr 05 '17 at 23:41
  • 2
    All the `strXXX_s()` functions are useful to make buffer overflows less likely, so your code will be safer. So it's not a bad idea to use them, except they're not portable. – Barmar Apr 05 '17 at 23:48

0 Answers0