Hi,
I'm still working on my VB->C conversion program, and am now struggling with Segmenation Fault errors.
This question isn't about that. I'm also getting some warnings regarding some calls of strrchr I'm doing. I got my current understanding of strrchr from the website cplusplus.com, specifically: http://www.cplusplus.com/reference/c...g/strrchr.html
Their code is as follows: -
char str[] = "This is a sample string";
-
char * pch;
-
pch=strrchr(str,'s');
-
printf ("Last occurence of 's' found at %d \n",pch-str+1);
-
return 0;
-
My code is as follows: -
char * pch;
-
....
-
#if _WIN32
-
{
-
pch=strrchr(gstrBottleFile,"\\"); //could I pass it char(92) instead?
-
}
-
#else
-
{
-
pch=strrchr(gstrBottleFile,"/"); //could I pass it char(47) instead?
-
}
-
#endif
-
The else statment gives me the following error when I compile this on Linux:
"warning: passing arg 2 of `strrchr' makes integer from pointer without a cast".
I basically hoping that someone can explain to me why this is happening, as its a warning, I decided to ignore it for now, but am still curious why this warning keeps popping up. And why only on the Linux side, and not the windows side as well.
Thanks,
Sitko.
5 1138
The second argument of strrchr() is a character. Not a string.
Try single quotes.
Thanks,
That did the trick. Just for the unix line, not the other, as it has two slashes (to dereference the slash).
As to the pch being a char instead of a pointer, later in the code I 'use' it as a string, in this debug statement:
//printf("%s , %s\n",gstrBottleFile,(pch+1));
and it works to print out everything AFTER the last slash...
Thanks again for the quick turnaround...
Are there any good references regarding identifying the cause of a segmatation fault error?
Thanks,
Sitko.
A good guess for a segfault is bad memory access. So you basically find the lines of code causing a segfault and see what memory is accessed.
By bad memory access, I mean things like going out of arrays (once out of the array, you are trying to read/write memory that isn't yours), bad pointers, and that sort of thing.
A good guess for a segfault is bad memory access. So you basically find the lines of code causing a segfault and see what memory is accessed.
By bad memory access, I mean things like going out of arrays (once out of the array, you are trying to read/write memory that isn't yours), bad pointers, and that sort of thing.
I did make some good progress on this issue, by bounding my string variables (character arrays). In the examples I've been referring to, they often just put" "char * Var", and apparently this isn't "liked" by the linux compliler, so I switch them to char Var[200]; and the segfaults moved further downstream...
Thanks,
Sitko.
That did the trick. Just for the unix line, not the other, as it has two slashes (to dereference the slash).
\\ is one char. That is, '\\'.
Remember, the \ is an escape sequence and it indicates that the symbol folllowing is a code. \\ is the \ character. It's the only way you can code it.
Dereference is used with respect to pointers.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Dave |
last post by:
After following Microsofts admonition to reformat my system before doing a
final compilation of my app I got many warnings/errors upon compiling an rtf
file created in word. I used the Help...
|
by: Gianni Mariani |
last post by:
I have a couple of template methods that take any integer type however,
the first "if" statement becomes a constant expression when T is an
unsigned type.
#include <limits>
template...
|
by: baustin75 |
last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie
only when debugging in php designer 2005
--------------------------------------------------------------------------------
...
|
by: Bob |
last post by:
Hi,
The compiler gives Warning 96 Variable 'cmdSource' is used before it has
been assigned a value. A null reference exception could result at runtime.
Dim cmdSource as SQlClient.SQLDataReader...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |