ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Problem when using the strchr function.
The code below result in a null value despite the fact that
a colon is in the string. This is incorrect
ip_address = strchr(ip_address_string, ':');
The code below result in an 'r' value because the letter
r is in the string. This is correct
ip_address = strchr(ip_address_string, 'r');
Hi itsme86. Thank you for your help.
I used the function s = strtok(ip_address_string, ":")
and then I used the function
ip_address = strchr(ip_address_string, ':') and that is why
it gives me a null value.
The function strtok kept a hidden static pointer.
When I called the strchr function afterward, the pointer points to null.
If I commented out the code s = strtok(ip_address_string, ":")
it gives a correct answer when I run the code
I am having a similar problem with strchr with SUSE Linux 10.1. The following code compiles and works fine on MS-Dos and SCO Unix 5.06 but generates a Segmentation fault on SUSE Linux 10.1.
welcome to linux questions. in the future please use code tags as they preserve the formatting and make the code alot easier to read.
as for your segfault, it might have something to do with you asking for a .
> fprintf(stdout,"Try entering 90.775\n");
and then looking for a -
> strchr(buffer,'-');
then you continue through converter() without verifying that p is valid. if you were to add this block after p = strchr(buffer, '-'); in converter.. you should see where you are going wrong.
Code:
if(!p)
{
printf("did not find char in string, bailing out\n");
return;
}
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.