Click here to Skip to main content
15,912,578 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionIs there an easy way to change "... text ..." to _T("... text ...") for whole project? [modified] Pin
transoft11-Jun-09 9:32
transoft11-Jun-09 9:32 
AnswerRe: Is there an easy way to change "... text ..." to _T("... text ...") for whole project? PinPopular
Randor 11-Jun-09 10:24
professional Randor 11-Jun-09 10:24 
GeneralThank you very much, Pin
transoft11-Jun-09 10:37
transoft11-Jun-09 10:37 
GeneralRe: Is there an easy way to change "... text ..." to _T("... text ...") for whole project? Pin
Rajesh R Subramanian11-Jun-09 10:45
professionalRajesh R Subramanian11-Jun-09 10:45 
QuestionProblem with sending keystroke to game. [modified] Pin
dirwir11-Jun-09 9:26
dirwir11-Jun-09 9:26 
AnswerRe: Problem with sending keystroke to game. Pin
Rajesh R Subramanian11-Jun-09 10:21
professionalRajesh R Subramanian11-Jun-09 10:21 
GeneralRe: Problem with sending keystroke to game. Pin
dirwir11-Jun-09 13:05
dirwir11-Jun-09 13:05 
Questioncreating a linked list Pin
steve_rm11-Jun-09 7:18
steve_rm11-Jun-09 7:18 
Hello,

I am creating a linked list. I have found that the best way to develop the linked list is to have the head and tail in another structure. My products struct will be nested inside this structure. And I should be passing the list to the function for adding and deleting. I find this concept confusing.

I have implemented the initialize, add, and clean_up. However, I am not sure that I have done that correctly.

When I add a product to the list I declare some memory using calloc. But I am thinking shouldn't I be declaring the memory for the product instead. I am really confused about this adding.

Many thanks for any suggestions,

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define PRODUCT_NAME_LEN 128

typedef struct product_data 
{
    int product_code;
    char product_name[PRODUCT_NAME_LEN];
    int product_cost;
    struct product_data_t *next;
}product_data_t;

typedef struct list 
{
    product_data_t *head;
    product_data_t *tail;
}list_t;

void add(list_t *list, int code, char name[], int cost); 
void initialize(list_t *list);
void clean_up(list_t *list);

int main(void)
{
    list_t *list = NULL;

    initialize(list);
    add(list, 10, "Dell Inspiron", 1500);
    clean_up(list);

    getchar();

    return 0;
}

void add(list_t *list, int code, char name[], int cost)
{
    // Allocate memory for the new product
    list = calloc(1, sizeof(list_t));
    if(!list)
    {
        fprintf(stderr, "Cannot allocated memory");
        exit(1);
    }

    if(list)
    {
        // First item to add to the list
        list->head->product_code = code;
        list->head->product_cost = cost;
        strncpy(list->head->product_name, name, sizeof(list->head->product_name));
        // Terminate the string
        list->head->product_name[127] = '/0';
    } 
}

// Initialize linked list
void initialize(list_t *list)
{
    // Set list node to null
    list = NULL;
    list = NULL;
}

// Release all resources
void clean_up(list_t *list)
{    
    list_t *temp = NULL;

    while(list)
    {
        temp = list->head;
        list->head = list->head->next;
        free(temp);    
    }
    list = NULL;
    list = NULL;
    temp = NULL;
}

AnswerRe: creating a linked list Pin
Maximilien11-Jun-09 7:59
Maximilien11-Jun-09 7:59 
AnswerRe: creating a linked list Pin
David Crow11-Jun-09 8:26
David Crow11-Jun-09 8:26 
QuestionRe: creating a linked list Pin
steve_rm11-Jun-09 16:30
steve_rm11-Jun-09 16:30 
AnswerRe: creating a linked list Pin
David Crow12-Jun-09 3:29
David Crow12-Jun-09 3:29 
QuestionRe: creating a linked list Pin
led mike11-Jun-09 8:28
led mike11-Jun-09 8:28 
AnswerRe: creating a linked list Pin
steve_rm11-Jun-09 16:35
steve_rm11-Jun-09 16:35 
QuestionRe: creating a linked list Pin
David Crow26-Jun-09 7:51
David Crow26-Jun-09 7:51 
Questionset the parameter of CRichEditCtrl ::SetWindowText() Pin
MrKBA11-Jun-09 5:18
MrKBA11-Jun-09 5:18 
AnswerRe: set the parameter of CRichEditCtrl ::SetWindowText() Pin
Stephen Hewitt11-Jun-09 5:58
Stephen Hewitt11-Jun-09 5:58 
GeneralRe: set the parameter of CRichEditCtrl ::SetWindowText() Pin
MrKBA11-Jun-09 6:01
MrKBA11-Jun-09 6:01 
GeneralRe: set the parameter of CRichEditCtrl ::SetWindowText() Pin
Michael Schubert11-Jun-09 6:12
Michael Schubert11-Jun-09 6:12 
GeneralRe: set the parameter of CRichEditCtrl ::SetWindowText() Pin
MrKBA11-Jun-09 6:40
MrKBA11-Jun-09 6:40 
GeneralRe: set the parameter of CRichEditCtrl ::SetWindowText() Pin
Michael Schubert11-Jun-09 20:50
Michael Schubert11-Jun-09 20:50 
Questioncan you find the problem?? Pin
August Brower11-Jun-09 5:10
August Brower11-Jun-09 5:10 
AnswerRe: can you find the problem?? Pin
CPallini11-Jun-09 6:58
mveCPallini11-Jun-09 6:58 
AnswerRe: can you find the problem?? Pin
chirag_chauhan11-Jun-09 19:08
chirag_chauhan11-Jun-09 19:08 
QuestionHow to debug a DLL () running on the remote server using Visual studio 2005 Pin
ptr_Electron11-Jun-09 3:15
ptr_Electron11-Jun-09 3:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.