How can I solve error C2374 in Visual C ++ ?

May 23, 2011 at 08:55:21
Specs: Windows 7
How can I solve error C2374 in Visual C ++ ?
Error C2374 : redefinition ,multiple initialization

#include<iostream>
#include<cstring>
using namespace std;
int main (void)
{
char str1[10]="Ali",str2[10]="Bassim" ;
int i;
i=strcmp(str1,str2);
char str2[10]="Ali";
i=strcmp(str1,str2);
char str1[10]="Dany";
i=strcmp(str1,str2);

return 0;}


See More: How can I solve error C2374 in Visual C ++ ?

Report •


#1
May 23, 2011 at 09:01:58
You've declared str1 and str2 as a char arrays twice. Omit the "char" the second time

str2[10] = "Ali";
str1[10] = "Dany";

But that's still not going to work, because now you're trying to assign character arrays (strs) to chars (str2[10] is a char). You need:

strcpy(str2, "Ali");
strcpy(str1, "Dany");

It should then compile OK. But it's still not going to do anything; you need to print the value of "i" each time to see what is happening.


Report •

#2
May 23, 2011 at 09:28:08
oh thank you very much , this was really helpful = )

Report •

Related Solutions


Ask Question