-1

After I compile it, it gives me an error on (ps:i am using devc++ 5.9.2 as the compiler, and one my friend use dev c++ 5.1.1, and she is able to compile).

[Warning] Deprecated conversion from string constant to 'char*' [-Wwrite-strings]

void switchSecondSelection(int selection){
int secondSelection;

    switch(selection){
    case 1:
    subMenu("Supplier Info",1);
 //   return secondSelection;
    break;
    case 2:
    subMenu("Customer Info",2);
 //   return secondSelection;
    break;
    case 3:
    subMenu("Medicine Info",3);

//  return secondSelection;
    break;
    case 4:
//      secondSelection = showReport("Report");
   break;
    case 5:
//      secondSelection = showBill("Bill");
    break;
    case 6:
    mainProgram(0);
    break;
    default:
    mainProgram(0);
    break;
}
cdomination
  • 605
  • 1
  • 7
  • 25
Tohsiba
  • 1
  • 2
  • devc++ is **not** a compiler. See [ask] and provide a [mcve]! – too honest for this site Jul 08 '16 at 12:41
  • 1
    By defining `subMenu` to take a `const char*` argument. – Weather Vane Jul 08 '16 at 12:42
  • Hi, Weather Vane, but how? i am still a Semester 1 Student in C,can u show me the code? – Tohsiba Jul 08 '16 at 12:45
  • Not until you show the function yourself. – Weather Vane Jul 08 '16 at 12:46
  • @Tohsiba if you are new here, please note that you flag someone by putting the `at` symbol before their name, like I did in this comment. – Weather Vane Jul 08 '16 at 12:51
  • @WeatherVane void subMenu(char title[256],int category); << you mean here? subMenu(const char title[256],int category);? but after i had changed the information, another error show up , and when i put in subMenu const ("Supplier Info",1); and its say [Error] expected ';' before 'const' – Tohsiba Jul 08 '16 at 13:00
  • Please post your code *in the question*, properly formatted and quoting the *exact* error message. In your comment it looks as though you have changed the function declaration (prototype). You also need to change the function definition (implementation). – Weather Vane Jul 08 '16 at 13:05
  • "i am still a Semester 1 Student in C" - What a lame excuse! There are enough C books available for free. If in doubt ask your teacher, that's what he is paid for. – too honest for this site Jul 08 '16 at 13:12
  • Possible duplicate of [How to get rid of \`deprecated conversion from string constant to ‘char\*’\` warnings in GCC?](http://stackoverflow.com/questions/59670/how-to-get-rid-of-deprecated-conversion-from-string-constant-to-char-warnin) – Bo Persson Jul 08 '16 at 13:41

1 Answers1

1

You don't show your subMenu function, but it most likely takes a char * as its first argument. Because it is not const, the function is free to modify what that argument points to. That doesn't work however for string constants which typically reside in a read-only section of memory.

Change the definition of subMenu to take a const char * for the first argument.

EDIT:

Find where subMenu is defined. It probably looks something like this:

void subMenu(char *name, int value)

Change it to this:

void subMenu(const char *name, int value)
dbush
  • 205,898
  • 23
  • 218
  • 273
  • can you show me the code? and how should i do it to change the definition of subMenu to take a const char? ,because i am still a Semester 1 student in C and i have no ideas how to complete this assignment – Tohsiba Jul 08 '16 at 12:47
  • nt mainMenu(); void subMenu(char title[256],int category); << you mean here? subMenu(const char title[256],int category);? but after i had changed the information, another error show up , and when i put in subMenu const ("Supplier Info",1); and its say [Error] expected ';' before 'const' – Tohsiba Jul 08 '16 at 12:56
  • @Tohsiba Look closely at what I wrote. I didn't say to put `const` after the function name when you call it. I said to put `const` right before `char` in the definition, i.e. `void subMenu(const char title[256],int category);`. This is the declaration, so you also need to change the definition which is where the body of the function `subMenu` is. – dbush Jul 08 '16 at 13:06