[Home] [Downloads] [Search] [Help/forum]

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  Programming
. -> [Folder]  General
. . -> [Subject]  beginner question.
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

beginner question.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by kenny31539   USA  (6 posts)  [Biography] bio
Date Wed 31 Mar 2010 10:38 PM (UTC)
Message
Ok, this might seem like a rather silly question. I'm not-so-new at coding, but I still don't know my tail-end from a hole in the ground. I've managed to track down and fix a few bugs since updating to ubuntu's Koala, but this one is simply giving me fits.

void Project_Handler::set_topwidth(void)
{
	Project_Data *project;
	string strbuf;
	if(!first_project)
	{
		topwidth = 0;
		return;
	}
	
	for(project = first_project; project; project = project->get_next())
	{
		strbuf = project->get_heading();
		if(topwidth < (int)strlen(strbuf.c_str()))
		{
			topwidth = strlen(strbuf.c_str());
		}
	}
	return;
}

Now, the error that it's throwing when I compile is strlen is undeclared in this scope. So, I tried the logical thing and tried declaring it...and it threw another error saying th at strlen can't be used as a descriptor or some such (I lost my password so waiting for the admin to show up)

Anyone familliar at all with this? OH! Idiota me...it's in swfotefuss.

Any help or advice (other than suicide or burning my fingertips off with a blowtorch) would be greatly appreciated. :)
[Go to top] top

Posted by Keberus   (31 posts)  [Biography] bio
Date Reply #1 on Wed 31 Mar 2010 11:33 PM (UTC)
Message
You might want to check if strings.h is declared at the top of the file. It should look like

#include <string.h>

[Go to top] top

Posted by kenny31539   USA  (6 posts)  [Biography] bio
Date Reply #2 on Wed 31 Mar 2010 11:35 PM (UTC)
Message
Ever...just really feel like an idiot? I took a look at the top of the file and...what do you know...the only header there was project.h Ok ok...so maybe I DO need to take a blowtorch to my fingers. Thanks a bundle! Soon as the admin comes around I'll let you know if it worked or not. :P
[Go to top] top

Posted by Nick Cash   USA  (626 posts)  [Biography] bio
Date Reply #3 on Thu 01 Apr 2010 01:50 AM (UTC)
Message
Your way is a little roundabout. You could always change:


strlen(strbuf.c_str())


to:


strbuf.length()


:)

~Nick Cash
http://www.nick-cash.com
[Go to top] top

Posted by kenny31539   USA  (6 posts)  [Biography] bio
Date Reply #4 on Thu 01 Apr 2010 02:54 AM (UTC)
Message
yeah, but:



	if(topwidth < (int)strlen(strbuf.c_str()))




is the line that's throwing the error. Tried changing it to


if(topwidth <strlen(strbuf.c_str) );

and putting


int strbuf]

earlier in the function, but then it gave me some other screwy error I can't remember at the moment.
[Go to top] top

Posted by Nick Cash   USA  (626 posts)  [Biography] bio
Date Reply #5 on Thu 01 Apr 2010 03:51 AM (UTC)

Amended on Thu 01 Apr 2010 03:55 AM (UTC) by Nick Cash

Message
strbuf is already declared as a string, you wouldn't want to define it as an integer.


if(topwidth <strlen(strbuf.c_str) );


There are a couple things wrong with that statement. First, if strlen is undeclared you will still get the same error you were before.

If you redefined strbuf to be an int then it would throw an error about calling c_str.

The correct way to call the c_str function is
strbuf.c_str()

So you are missing parens and it would give you a syntax error.

The semi-colon would not trigger an error, but would almost certainly not do what you would expect. It signifies an empty block, thus nullifying the code the if statement was supposed to execute. Conditional statements should not have semi-colons after them unless it is intended, which is typically rare.

I see no reason why this wouldn't work:

void Project_Handler::set_topwidth(void)
{
	Project_Data *project;
	string strbuf;

	if(!first_project)
	{
		topwidth = 0;
		return;
	}
	
	for(project = first_project; project; project = project->get_next())
	{
		strbuf = project->get_heading();

		if(topwidth < strbuf.length())
		{
			topwidth = strbuf.length();
		}
	}
}


~Nick Cash
http://www.nick-cash.com
[Go to top] top

Posted by kenny31539   USA  (6 posts)  [Biography] bio
Date Reply #6 on Sat 03 Apr 2010 06:13 PM (UTC)
Message
Turned out that adding strings.h to the header worked like a charm. :) Much appreciate for all the help! I'm sure that I'll come up with a million more questions and seeking advice in the very near future. :)
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


4,591 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]