[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.0

sorted linked list in C

Asked by Mytix in C Programming Language, Microsoft Visual C++

Tags: linked, list

hi, i have a flat file with names and item they pruchased (delimited by either a /,\,{,or}) which look like this:
john smith/soap
john brown/toilet paper
john smith/toilet paper
bruce smith/paper towel

etc etc
i need to read this txt file (m.txt) and put it into a sorted link list with the struct property(assuming that none of the names exceed 100 in length):

struct customer
{
      struct customer *nextCustomer;
      char name[100];
      int appear;
};
typedef struct customer custNode;

the appear property is used if the customer name comes out more than once, then the appear should be incremented. note that the item the person purchased is not stored (this is done in another sub-system)
im able to read the file, but i cant split it into delimited parts and sort the linked list, nor can i increment the appear for the corresponding customer. here is what my code looks like:


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

#define SLENGTH 100

struct customer
{
    struct customer *nextNode;
    char name[SLENGTH];
    int appear;
};

typedef struct customer custNode;

FILE *fin;

void exitIfFault(FILE *fp,char file[]);
FILE* fileOpen(char *file, char *mode);
void countC(char file[]);
custNode* createNode(char *custData);

int main(int args, char *arg[])
{

    if (args != 2)
    {    
          printf("\nSyntax : count filename\n");
         return 1;
    }    
     countC(arg[1]);
    return 0;
}

void countC(char file[])
{
    char tempo;

    FILE *fp = fileOpen(file, "r");

    custNode *startList=NULL;
    custNode *tempPtr, *tailPtr = startList;
    custNode aWord;
   
     while (!feof(fp))
    {
         fscanf(fp, "%s", &tempo);
         tempPtr = createNode(&tempo);
          if (tailPtr == NULL)
         {
              startList = tailPtr = tempPtr;
         }
         else
         {
              if (exists(tempPtr->name,startList))
              {
                   while (startList != NULL)
                   {
                        if (strcmp(tempPtr->name,startList->name)==0)
                        {
                             startList->appear++;
                        }
                        startList = startList->nextNode;                        
                    }
              }
              else
              {
                   tailPtr->nextNode = tempPtr;
                   tailPtr = tempPtr;
                   
              }
         }

    }
    fclose(fp);
          
}

custNode* createNode(char *custData)
{
  /*create new node for linked list. check malloc worked correctly and ensure node pointer set to NULL
   */

custNode *tempPtr;

tempPtr = (custNode*) malloc(sizeof(custNode));
if(tempPtr == NULL)
{
  printf("Memory allocation error\n");
  exit(EXIT_FAILURE);
}
strcpy(tempPtr->name,custData);
tempPtr->nextNode = NULL;

return tempPtr;
}

void exitIfFault(FILE *fp,char file[])
{
    char temp;
    while (!feof(fp))
    {
         fscanf(fp, "%c", &temp);
         if (temp != '\n')
         {
              printf("Error reading from %s\n",file);
              fclose(fp);
              exit(1);
         }
    }

}

FILE* fileOpen(char *file, char *mode)
{
    FILE *fp = fopen(file,mode);
    if ( fp == NULL)
    {
         printf("\nError - Unable to access %s\n",file);
         exit(1);
    }
    return fp;
}

Note that the link list is stored in memory and will be used in other sub-systems.
thanks for your help

[+][-]05/25/04 08:53 PM, ID: 11158433Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05/26/04 12:02 AM, ID: 11159152Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05/26/04 01:37 AM, ID: 11159626Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05/26/04 02:46 AM, ID: 11159924Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05/26/04 02:51 AM, ID: 11159945Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05/26/04 02:56 AM, ID: 11159964Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05/26/04 03:40 AM, ID: 11160162Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05/26/04 12:36 PM, ID: 11164879Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05/26/04 12:51 PM, ID: 11165042Assisted Solution

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 30-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]05/26/04 07:32 PM, ID: 11167840Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05/26/04 08:53 PM, ID: 11168157Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05/26/04 09:21 PM, ID: 11168301Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05/26/04 09:56 PM, ID: 11168436Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05/27/04 01:48 AM, ID: 11169451Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05/27/04 03:45 AM, ID: 11170034Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05/27/04 08:02 AM, ID: 11172362Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05/27/04 08:49 AM, ID: 11172894Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05/27/04 09:39 AM, ID: 11173360Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05/27/04 09:41 AM, ID: 11173369Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05/27/04 09:53 AM, ID: 11173448Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05/27/04 09:54 AM, ID: 11173456Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05/27/04 10:33 AM, ID: 11173806Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05/27/04 10:50 AM, ID: 11173975Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: C Programming Language, Microsoft Visual C++
Tags: linked, list
Sign Up Now!
Solution Provided By: brettmjohnson
Participating Experts: 5
Solution Grade: A
 
 
Loading Advertisement...
20091111-EE-VQP-89