C problem struct and string


Posted on 16th Feb 2014 07:03 pm by admin

Hi guys,

This is my first post and I'm hoping the experts here can help me solve my problem.

Did you know?Explore Trending and Topic pages for more stories like this.
- I'm trying to create a linked list in C and the codes look like this:

#include "stdio.h"
#include
#include
using namespace std;

struct dir_list
{
int level;
string dir_name;
struct dir_list * head;
struct dir_list * tail;
};

typedef struct dir_list * dir;

void main()
{
dir curr;

curr=(dir)malloc(sizeof(string)+sizeof(dir));
curr->level=0;
curr->dir_name="test ";
curr->head=NULL;
curr->tail=NULL;
}

The problem with this code happens at the string assignment curr->dir_name="test "; and the executable will stop responding once run. I suspect the problem could be caused by the size of malloc but the result stays the same after I increased that number.

Can anyone explain to me what the problem is?

Greatly appreciated!
No comments posted yet

Your Answer:

Login to answer
329 Like 5 Dislike
Previous forums Next forums
Other forums

turning an array into a string then poping it into a db
Hi im just wondering how you get a requested array into a single string then pop it into the db so f

Issue Parsing XML into table
Hello all,

Im a bit new to php and new to phpfreaks. But thanks in advance for the help!
<

does anyone know a php script to send mail using gmails/googles free smtp server
cause i heard u can do that but i dont know how

Need Successful Return
Hello I am currently working a form here, and I have everything figured out except when I click the

The repetition structure: the while statement not working
New programming student, have assignment as follows:
A restaurant has 4 lunch combos for custom

tell csv import script to ignore blank rows?
Hi i have the below script but i get an error if a row is blank ie a return in the csv file at the e

RSS feed - FeedList for WordPress
Hi,

I'm trying to alter the FeedList plugin for WordPress so that I can click on the title of

PHP and MySQL on intranet?
Is it possible to use both these on an intranet network?

Help with syntax
Hi all!

The $bridge variable is not getting passed while it is contained in the line below:

Replacing a string on click of a button
Hi! Is there a way to replace a string on a click of a text link?

This is what I've come up w

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash