-2

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.

Edited by Nick Evan: Added code-tags

Votes + Comments
11 posts and still have not figured out how to use code tags.
2
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by Ancient Dragon
0
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;
}
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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.