Hi,
I've been working in C++ and java .... i m fond of using String data type .... but in C I've to use char array as string and have to pass it to a function as string
its creating some confusions plz help

void function( charArray comes here  )
{
char localArray[10]="my String";
// here i have to use that charArray as string and have to compare it with
// localArray.
}

int main()
{
char charArray[10];
function(  pass charArray here  );

return 0;
}

plz provide the syntax to pass, get and compare charArray.
Thanks.

Ancient Dragon commented: 11 posts and still have not figured out how to use code tags. -5

Recommended Answers

All 3 Replies

void function( char passedArray[])
{
char localArray[10]="my String";
// here i have to use that charArray as string and have to compare it with
// localArray.
    
    if( strcmp(localArray, passeedArray)== 0)
         cout << "The two strings are the same\n";
}

int main()
{
char charArray[10] = "Hello";
function( charArray);

return 0;
}

hhmmm thnkss .. its solved ... can u tell me one more thing plz ... ??

if we want to read and append a text file at the same time we open it in a+ mode
i.e fopen("file.txt","a+");

but i want to open a file, search it and want to delete a pirticular string from it .... what mode should i open it in???

input file.txt:
This_is
My_Text
File_Contant


After code runs and searches for "My_Text" the file looks like:
This_is
File_Contant

you will have to completely rewrite the file.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.