current position:Home>Warning during compilation: deprecated conversion from string constant to 'char *' [- wwrite strings];

Warning during compilation: deprecated conversion from string constant to 'char *' [- wwrite strings];

2022-02-02 19:50:48 CSDN Q & A

How to solve it
#include<stdio.h>
#include<string.h>
int f(char *s[],int n)
{
char *temp;
for(int i=0;i<n;i++){
for(int j=i+1;j<n;j++){
if(strcmp(s[i],s[j])>0){
temp=s[i];
s[i]=s[j];
s[j]=temp;
}
}
}
}
int main()
{
char *s[]={"good","better","well","see","luck"};
int n=5;
f(s,n);
for(int i=0;i<n;i++){
printf("%s\n",s[i]);}
return 0;
}

closed




Refer to the answer 1:
#include<stdio.h>#include<string.h>int f(char* s[], int n){    char* temp;    for (int i = 0; i < n; i++) {        for (int j = i + 1; j < n; j++) {            if (strcmp(s[i], s[j]) > 0) {                temp = s[i];                s[i] = s[j];                s[j] = temp;            }        }    }    return 0;}int main(){    char* s[] = { "good","better","well","see","luck" };    int n = 5;    f(s, n);    for (int i = 0; i < n; i++) {        printf("%s\n", s[i]);    }    return 0;}



Refer to the answer 2:



Refer to the answer 3:

char tem;
No, * Number




Refer to the answer 4:

copyright notice
author[CSDN Q & A],Please bring the original link to reprint, thank you.
https://en.primo.wiki/2022/02/202202021950467792.html

Random recommended