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

SAP Treasury - Commodities
We are running SAP ECC 6.0 with Treasury Activated.
EA-FIN is also activated (SFW5).

Multiple if statements
Ok so seems basic but for some reason I'm not doing it right. What I want is to be able to have 2 se

Load Animated Image while cache is serve
I have a page that loads up using cache and took about 1 to 2 minutes before it loads to the page. <

getting most records by count
Code: [Select]<?php

$connect = mysql_connect("localhost","dam

why is it over writing
Code: $filepaths[] = $_FILES['new_image'];
foreach ($filepaths as $filepath)
{
$imagename =

Combining refCursors and Summing
Given the following DDL:

CREATE TABLE FOODSALESTEST ("WEEKNBR" NUMBER, "ST

Convert .fdf to .pdf
I currently have a web form that uploads the form data to an .fdf file and emails it.

However

phpMailer not working ..........
HI,
I was playing with the phpMailer script and tried to send a smiple mail using their test scri

BAPI BBP_INB_DELIVERY_CREATE - material number missing in delivery
Hi Experts,

I was able to successfully create an Inbound delivery with reference to a PO

how do i display data on a page from mysql
1 - do i use this code at the top of each of my page i wish to only alow access if there as been a s

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