Note that there are some explanatory texts on larger screens.

plurals
  1. POreading data file into binary tree
    primarykey
    data
    text
    <p>my program seems to only read part of the input data file </p> <p>this is my code:</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;ctype.h&gt; #include "BST_ADT.h" // Structure typedef struct { char* name; char* market; char* initial; float stock; }COMPANY; // Prototype Delarations void addComp (BST_TREE* list); void deleteComp (BST_TREE* list); void findStu (BST_TREE* list); void printList (BST_TREE* list); int compareStu (void* stu1, void* stu2); void processStu (void* dataPtr); int main (void) { // Local Definitions BST_TREE* list; // Statements list = BST_Create(compareStu); addComp(list); deleteComp(list); findStu (list); printList(list); return 0; } /*===================== addComp =========================*/ void addComp (BST_TREE* list) { // Local Declarations COMPANY* stuPtr; FILE* fp; char fileName[25]; char buffer [100]; // Statements stuPtr = (COMPANY*)malloc (sizeof (COMPANY)); stuPtr-&gt;name = (char*) malloc(128 * sizeof(char)); stuPtr-&gt;market = (char*) malloc(128 * sizeof(char)); stuPtr-&gt;initial = (char*) malloc(128 * sizeof(char)); printf("Enter the file name: "); gets(fileName); fp = fopen(fileName, "r"); if(fp == NULL) { printf("Error cannot open the file!\n"); exit(101); } while(fgets(buffer, 100, fp) != NULL) { if (!stuPtr) printf("MEmory overflow!\n"), exit(101); sscanf(buffer, "%s %s %s %f ", stuPtr-&gt;name, stuPtr-&gt;market, stuPtr-&gt;initial, &amp;(stuPtr-&gt;stock)); BST_Insert(list, stuPtr); } // end while } //addStu /*===================== deleteComp =========================*/ void deleteComp (BST_TREE* list) { // local definitions char name[100]; char* namePtr = (char*) malloc(128 * sizeof(char)); namePtr = name; // statements printf("Enter Company name: "); scanf ("%39s", namePtr); if (!BST_Delete (list, namePtr)) printf("ERROR: No Company: %0\n", *namePtr); } // deleteStu </code></pre> <p>this is my input data from text file :</p> <pre><code>Target Corporation; NYSE TGT 44.14B PriceSmart, Inc.; NASDAQ PSMT 721.96M Eastman Kodak Company; NYSE EK 5.14B Concord Camera Corp.; NASDAQ LENS 25.43M Siemens AG (ADR); NYSE SI 123.13B 3M Company; NYSE MMM 56.47B Toshiba Corporation; OTC TOSBF 24.43B Tyco International Ltd.; NYSE TYC 19.91B Textron Inc.; NYSE TXT 13.90B PHH Corporation; NYSE PHH 1.11B Activision, Inc.; NASDAQ ATVI 8.07B The Walt Disney Company; NYSE DIS 61.27B </code></pre> <p>at the end of the addComp function </p> <pre><code>name contain 'The' market contain 'Walt initial contain 'Disney and stock contain 6.09 </code></pre> <p>this is not what the function was intended to do </p> <p>instead, if this function was done right:</p> <pre><code>name should contain 'The Walt Disney Company' market contain 'NYSE' initial contain 'DIS' and stock contain '61.27B </code></pre> <p>'</p> <p>what did I do wrong with the addComp function? Was it necessary to use token in order to read these data into binary tree?</p> <p>thank in advance for helping</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload