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.

- 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

onClick='location.href=index.htm'> not working
Below is my code:

echo "<input type='button' value='redirect' onClick='location.h

Checking if variable is 0 as opposed to NULL/Empty...
I'm trying to write some code that will retrieve a user's access level from my database and if it do

user data not transferring to new page
I'm a PHP learner. After an index.php page, the user goes to a login.php page. Both pages seem to

need help in update query
i create a form for update. there are 8 columns in my mysql table. on my main page all the data is r

how can i make a .gif images for my site
Dear Friends ,

Pls solve my problem , I am starting making new site but i dont know how can i

ob_ dynamic content
i was wondering about the potential to use ob to create a <div then remove it when the page

mySQL and PHP search
Hello,
I am trying to code a project and ran into a brick wall with one of my pages. I am pretty

Troubles with a spider class
I am building a spider that will crawl through random whitepages (eg. anywho.com, switchboard.com, w

how make 2 column in table with data tybe long row
hi every one

I want make in my table 2 column with data tybe long raw

how thi

Dynamic Array using glob?
Is there an easier way to do this?

I am trying to get create a dyamic array based on files wi

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