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

Dynamic links in an include file
I am working on a small piece of code that counts records from a database and displays the result to

PHP header help!
Hi all I am trying to get this php page to refresh every 5 seconds on my phone which is an aastra 48

BB_Code error
I'm having a problem with a custom built function and keep getting this error:


Warning: M

php is not recognized as an internal or external command
Hello,

I am trying to bake the code in CakePHP through my console.
I have changed my Path

SESSION question
I am building an application , a directory for auctions.
For SEO i made a script which copies a p

How to generate a random array of integers subject to a certain constraint
I am writing a program that asks the user to enter an integer N and then generates a random array of

Batch update record with Pagination
Hoping someone can help me with this issue I'm having, im trying to batch update records from a resu

php form help
Hey,

I use a control file to set my meta tags and titles

Here's an example
Code: &a

Header redirect
Hello ive got a problem ive got form with its action set to itself.
Code: <form id="f

PHP Include w/If IE Condition Statement?
I was having a problem with Internet Exploder (big surprise, right?) displaying my drop down menus i

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