Zar Cab
Zar Cab

Reputation: 1

C, String array wont deprecated conversion from string constant to 'char*'

I have a simple program trying to print out some arrays and calculations but when trying to use string array I keep getting the same Message

This is the String Array

char *names[]={"Armstrong","Burns","Cousins","Duggan","Evans",
    "Field","Garnett","Hadfield","Johnston","Lovett","McDonald","Petersen","Singh"};

Function and prototype

void printFunction(char*, int *, int *, int, int);

void printFunction(char* names, int income, int numMembers, int povertylevel,
    int totalavg) {

  char *avgInc = " ";
  if (income < povertylevel) {
    if (income + 5000 < povertylevel) {
      avgInc = "****";
    } else {
      avgInc = "***";
    }
  }

  else if (income > totalavg + 10000) {
    avgInc = "**";
  } else {
    avgInc = "*";
  }

  printf("%-11s %-10d %-8d %s \n", names, income, numMembers, avgInc);
}

Main call

printFunction(*names,income,numMembers, povertylevel, averageIncome);

Upvotes: 0

Views: 60

Answers (1)

Humac
Humac

Reputation: 81

Your function declaration should be something like this:

void printFunction(char**,int ,int , int , int );

Because you've got array of string arrays so 1st argument must be double pointer. I'm not sure how you want print names but with pointer arithmetic:

*(names+i)

to print all names.

Upvotes: 1

Related Questions