473,387 Members | 1,440 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

help with warnings/and C stuff

140 100+
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:
Expand|Select|Wrap|Line Numbers
  1. char str[] = "This is a sample string";
  2.   char * pch;
  3.   pch=strrchr(str,'s');
  4.   printf ("Last occurence of 's' found at %d \n",pch-str+1);
  5.   return 0;
  6.  
My code is as follows:
Expand|Select|Wrap|Line Numbers
  1. char * pch;
  2. ....
  3. #if _WIN32
  4.     {
  5.         pch=strrchr(gstrBottleFile,"\\");  //could I pass it char(92) instead?
  6.     }
  7. #else
  8.     {
  9.         pch=strrchr(gstrBottleFile,"/"); //could I pass it char(47) instead?
  10.     }
  11. #endif
  12.  
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.
Nov 5 '07 #1
5 1138
weaknessforcats
9,208 Expert Mod 8TB
The second argument of strrchr() is a character. Not a string.

Try single quotes.
Nov 5 '07 #2
sitko
140 100+
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.
Nov 5 '07 #3
oler1s
671 Expert 512MB
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.
Nov 6 '07 #4
sitko
140 100+
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.
Nov 6 '07 #5
weaknessforcats
9,208 Expert Mod 8TB
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.
Nov 6 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

21
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...
11
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...
8
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 -------------------------------------------------------------------------------- ...
34
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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...
0
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...
0
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
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,...
0
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...
0
Oralloy
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,...
0
jinu1996
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.