|
Help in passing the path to a C function - URGENT
Author |
Message |
Uma Veerama #1 / 5
|
 Help in passing the path to a C function - URGENT
Hi All, I have a requirement to pass the path along with the filename to a function to perform some read operations. I might use this function(as library) in Visual Basic as well as any C/C++ program.The function definition goes like this : int ReadContent(char *filename); This function reads the contents of the file name which I pass as the parameter. This function is called like this : int result; result = ReadContent("C:\\New\\Readme.txt"); In VB, the programmer might give the path name as "C:\New\Readme.txt" and the function call will not work. I don't have any control over the client program and this function resides in a library. So, can I do something in the library program by which I can replace the single back slash with double slash ? Is it possible or not ? Thanks in advance. Regards Uma PS: If I pass a string with a single back slash in it, it is actually omitted and it comes into the library as c:NewReadme.txt , so even if I want to replace the single backslash character with 2 backslash characters, I am not able to do that in the library where the function resides.
|
Tue, 18 May 2004 05:33:14 GMT |
|
 |
Gordon Burdi #2 / 5
|
 Help in passing the path to a C function - URGENT
Quote: >Hi All, > I have a requirement to pass the path along with the filename to a >function to perform some read operations. I might use this function(as >library) in Visual Basic as well as any C/C++ program.The function >definition goes like this : >int ReadContent(char *filename); >This function reads the contents of the file name which I pass as the >parameter. >This function is called like this : >int result; >result = ReadContent("C:\\New\\Readme.txt");
This passes the string: C:\New\Readme.txt to the function. You need the double backslashes BECAUSE THIS TEXT IS IN A QUOTED STRING CONSTANT, not because you are passing a string. Quote: >In VB, the programmer might give the path name as "C:\New\Readme.txt" >and the function call will not work.
If you pass that value NOT AS A QUOTED STRING CONSTANT but as a character array into which you have read user input, it should work fine. Quote: >I don't have any control over the >client program and this function resides in a library. So, can I do >something in the library program by which I can replace the single >back slash with double slash ? Is it possible or not ?
If you are passing a character array into which you have read user input, you don't need to do this. Quote: >Thanks in advance. >Regards >Uma >PS: If I pass a string with a single back slash in it, it is actually >omitted and it comes into the library as c:NewReadme.txt , so even if
If you pass a QUOTED STRING CONSTANT with a single back slash in it, it is actually omitted and it comes into the library as c:NewReadme.txt. If you pass a character array containing those characters, the backslash will stay put. Quote: >I want to replace the single backslash character with 2 backslash >characters, I am not able to do that in the library where the function >resides.
Gordon L. Burditt
|
Tue, 18 May 2004 06:47:07 GMT |
|
 |
CBFalcone #3 / 5
|
 Help in passing the path to a C function - URGENT
Quote:
> I have a requirement to pass the path along with the filename > to a function to perform some read operations. I might use this > function (as library) in Visual Basic as well as any C/C++ > program.The function definition goes like this : > int ReadContent(char *filename); > This function reads the contents of the file name which I pass > as the parameter. > This function is called like this : > int result; > result = ReadContent("C:\\New\\Readme.txt"); > In VB, the programmer might give the path name as "C:\New\Readme.txt" > and the function call will not work. I don't have any control over > the client program and this function resides in a library. So, can > I do something in the library program by which I can replace the > single back slash with double slash ? Is it possible or not ?
You don't have any problem. The doubled backslashes are for the benefit of the C compiler in creating the string in the first place, and only single backslashes show up in the actual parameter passed. --
Available for consulting/temporary embedded and systems. (Remove "XXXX" from reply address. yahoo works unmodified)
|
Tue, 18 May 2004 08:52:59 GMT |
|
 |
Kaz Kylhe #4 / 5
|
 Help in passing the path to a C function - URGENT
Quote:
>Hi All, > I have a requirement to pass the path along with the filename to a >function to perform some read operations. I might use this function(as >library) in Visual Basic as well as any C/C++ program.The function >definition goes like this : >int ReadContent(char *filename); >This function reads the contents of the file name which I pass as the >parameter. >This function is called like this : >int result; >result = ReadContent("C:\\New\\Readme.txt"); >In VB, the programmer might give the path name as "C:\New\Readme.txt" >and the function call will not work. I don't have any control over the >client program and this function resides in a library. So, can I do >something in the library program by which I can replace the single >back slash with double slash ? Is it possible or not ?
The double slash is a *written representation* of a single slash character; that written representation appears only in program source. It is the object that is manipulated by the C program, not its source code representation. Similarly, the quotes are also part of the written representation of a string literal; they are also not part of the string object. How you specify string data in Visual Basic source, and how Visual Basic string objects must be treated when passing into a C module, these concerns are discussion topics for a Visual Basic newsgroup. The C language doesn't define any interface to Visual Basic.
|
Tue, 18 May 2004 09:09:39 GMT |
|
 |
Barry Schwar #5 / 5
|
 Help in passing the path to a C function - URGENT
Quote:
>Hi All, > I have a requirement to pass the path along with the filename to a >function to perform some read operations. I might use this function(as >library) in Visual Basic as well as any C/C++ program.The function >definition goes like this : >int ReadContent(char *filename); >This function reads the contents of the file name which I pass as the >parameter. >This function is called like this : >int result; >result = ReadContent("C:\\New\\Readme.txt"); >In VB, the programmer might give the path name as "C:\New\Readme.txt" >and the function call will not work. I don't have any control over the >client program and this function resides in a library. So, can I do >something in the library program by which I can replace the single >back slash with double slash ? Is it possible or not ? >Thanks in advance. >Regards >Uma >PS: If I pass a string with a single back slash in it, it is actually >omitted and it comes into the library as c:NewReadme.txt , so even if >I want to replace the single backslash character with 2 backslash >characters, I am not able to do that in the library where the function >resides.
In c, a string is simply an array of char terminated with a '\0'. Is it the same in VB? I thought it used an array of char preceded by a length. <<Remove the del for email>>
|
Tue, 18 May 2004 11:30:18 GMT |
|
|
|