C :: Parsing Tokens In File Lines Into A Linked List Of Data
Sep 20, 2013
I have been attempting to store mathematical functions in a file by parsing them into a linked list with a variable sized char ** array as my storage device. I have ran into problems with the memory management detail. The program crashes before output is flushed to the console, so printf() wasn't a debugging option. Neither is my actual debugger, since it seems to get a SIGTRAP every time. I have my warnings turned all the way up, but no errors or warnings are appearing. The part I know works is the actual code that opens the file and gets a line from the file. As far as the two functions that implement the linked list, that is most likely where the problem lies. My current attempt is basically to store the size of the dynamic array in the structure and keep resizing it until there are no more tokens. Then I will store the number of elements of the array in the structure and move on to the next node.
Here is my text file I use :
Code:
sqrt( 25 ); pow( 6 ); sin( 2 );
pow( 4 ); tan( pow( 2 ) ); Main.c :
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct file_data
[Code]...
View 7 Replies
ADVERTISEMENT
Mar 26, 2015
I have a data file that looks like:
111111111
Lisa
Porter
3
ENEE 114
CMSC 412
ENME 515
333333333
Alex
Simpson
1
CMSC 412
***
In the form student ID and then first name last name number of courses and finally the course code(s). Im currently attempting to read these into linked lists with the following code:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct CourseInfo {
int courseID;
char courseName[30];
[Code] ......
I get no errors or warnings however when i print this out i get:
111111111
Lisa
Lisa
Porter
3
ENEE 114
CMSC 412
ENME 515
And then the program crashes. So i know that for some reason the problem is the
fgets(rootPtr->FirstName, 22, p);
But I do not know why because it seems to work for the other fgets. I also want to know why the while loop never runs and it crashes instead.
View 14 Replies
View Related
Aug 27, 2014
In the program I'm writing, I'm creating a linked list of students with individual data read from a file. At the moment, I have written two functions to accomplish this; one that creates a student node and fills it from a line file, and a second that calls on the first to create a linked list. It seems to work fine except for one thing; It seems that EOF is being reached first, but the function continues on anyways? Here is my code so far...
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct student
// Declaring student structure globally.
[Code] .....
And here is what the input file would look like...
Thui Bhu, 100, 90, 80, 100, 89, 99, 88
Ariana B. Smith, 90, 90, 100, 100, 99, 100, 95
Emily Gonzales, 100, 90, 100, 70, 78, 78, 80
Jennifer L, 80, 90, 90, 100, 89, 99, 85
Maria Jones, 65, 72, 77, 68, 62, 70, 65
Bill Gates, 60, 54, 38, 62, 65, 60, 50
Escobar Morris, 83, 77, 88, 76, 79, 72, 76
Anne Latner, 80, 80, 85, 95, 90, 95, 98
John Doe, 45, 87, 88, 89, 67, 96, 79
And here is what the output is...
EOF
EOF in create_record
Thui Bhu: 100 90 80 100 89 99 88
Ariana B. Smith: 90 90 100 100 99 100 95
Emily Gonzales: 100 90 100 70 78 78 80
Jennifer L: 80 90 90 100 89 99 85
Maria Jones: 65 72 77 68 62 70 65
Bill Gates: 60 54 38 62 65 60 50
Escobar Morris: 83 77 88 76 79 72 76
Anne Latner: 80 80 85 95 90 95 98
John Doe: 45 87 88 89 67 96 79
Press any key to continue . . .
View 2 Replies
View Related
Jun 9, 2013
I'm trying to solve the following problem:
Given a query, find all possible tokens, i.e. query-splits
Example:
query = New York Hotel
tokens = {New, York, Hotel, New York, New Hotel, ...., New Hotel York, Hotel New York, ...}
Given a query with word count n, the total number of tokens is:
n + n*(n-1) + n*(n-1)*(n-2) + ... + n! (any explicit formula available for this sum?)
Now, I have came across various code snippets to generate permutations for a string, but never for a sentence.
View 13 Replies
View Related
Aug 26, 2014
Requirements in filtering the text file.
1. first my professor required me NOT to change the MAIN function(because he made it)
2. I have to make 3 getlogs() STRING FUNCTIONS:
a. string getlogs(); - accepts no paramters, SHOWS ALL THE CONTENTS OF TEXT FILE
b. string getLogs(const string & a); - accepts 1 parameter -SHOWS ONLY THE LINE WHICH CONTAINS THE SPECIFIED DATE FROM MAIN FUNCTION which is "2014-08-01"
c. string getLogs(const string & b, const string & c); - accepts 2 parameters, SHOWS ONLY THE LINES FROM THE DATE START to DATE END specified at THE MAIN FUNCTION which is date start-"2014-08-01";DateEnd = "2014-08-10";
3. all COUT should be in the MAIN FUNCTION
TEXTFILE CONTAINS:
2014-08-01 06:13:14,Name,4.5,CustomUnit,CustomType
2014-08-02 06:13:14,Name,4.5,CustomUnit,CustomType
2014-08-03 06:13:14,Name,4.5,CustomUnit,CustomType
2014-08-04 06:13:14,Name,4.5,CustomUnit,CustomType
[Code] .....
my codes so far:
//MAIN
#include <iostream>
#include <string>
#include <fstream>
#include <dirent.h>
[Code].....
View 1 Replies
View Related
Feb 6, 2014
I am wanting to be able to add as many different instances of data, while the user has not stated 'n', but then it only ever writes back to the screen the input for the last set of data. Where as I want to display back to the screen all the data that has been entered.
Code:
#include <iostream>
#include <string>
/*Function Declaration*/
void createItem();
void returnItem();
//Items structure
[code]...
View 6 Replies
View Related
Jan 4, 2014
I am parsing a binary data file by casting a buffer to a struct. It seems to work really well apart from this one double which is always being accessed two bytes off, despite being in the correct place.
Code:
typedef struct InvoiceRow {
uint INVOICE_NUMBER;
...
double GROSS;
...
char VAT_NUMBER[31];
} InvoiceRow;
If I attempt to print GROSS using printf("%f", row->GROSS) I get 0.0000. However, if I change the type of GROSS to char[8] and then use the following code, I am presented with the correct number...
Code:
typedef struct example {
double d;
}
example;
example *blah = (example*)row->GROSS;
printf("%f", blah->d);
View 7 Replies
View Related
Mar 30, 2014
For a project we are given a file with a couple of thousand lines of values, each line having 9 different numbers.
I want to create a for/while loop that, for each loop, stores the 8th and 9th integer of a line as a variable so that I can do some calculations with them. The loop would then move onto the next line, store the 8th and 9th numbers of that line as the same variable, so that I can do the same calculation to it, ending when I've run out of lines.
My problem is less to do with reading the file, I'm just confused how I'd tell it to take only the 8th and 9th value from each line.
View 5 Replies
View Related
May 27, 2013
I have made a Student record system in c++ using the concept of linked list. The program will take the student id, name and marks for 3 different exams. Then it will calculate the aggregate percentage based on those exams marks and display the relevant message according to the aggregate percentage. All is going well. But there is only one problem. When I modify the student record especially the marks, it doesn't change the aggregate percentage of that specific record. It shows the old one. Similarly the relevant message doesn't change too.
Code:
struct student{
int id;
char name[MAX];
string status;
double aggr;
int matric_marks, inter_marks, entryTest_marks;
[Code] .....
View 3 Replies
View Related
Aug 6, 2014
How can I search the data? I want to get the output like this.
============================== Enter a data to search: 44 DATA FOUND! ==============================
Code:
#include <iostream>
using namespace std;
struct node {
[Code].....
View 1 Replies
View Related
Feb 9, 2015
I am unable to insert data in a linked lists. Show function is not working.
insert
Code:
#include<stdio.h>
#include<stdlib.h>
typedef struct node{
int data;
struct node *next;
[Code] .....
View 7 Replies
View Related
Mar 20, 2014
The input is in the following format
5
1 2 9.0
1 3 12.0
2 4 18.0
2 3 6.0
2 5 20.0
3 5 15.0
0
1 5
The first number is the number of vertexes in the graph. Then next lines up to 0 are the edges of the graph. With the first and second numbers being the vertexes and the third being how far the edge is between them. Trying to read in the data and store the edges into there locations in the List adjacency for that vertex. This example would make a graph with five vertexes with edges from 1 to 2&3. 2 to 4&3&1 etc. It also stores in the opposites ex 2 1 9.0.
When reading it in and printing it back out it seems that it is only storing the last data entered for that vertex. EX. When trying to print out the data read in i only get 1 3 12.0, 2 5 20.0, 3 5 15.0, ( 4 2 18.0, 5 3 15.0 would show up if `if(i<n)` was removed it is there so it does not show duplicate edges). what I am doing incorrect?
// CSCI 3300
#include <cstdio>
using namespace std;
struct ListCell
{
ListCell* next;
int vertex;
double weight;
ListCell(int v, double w, ListCell* nxt)
[Code]...
View 1 Replies
View Related
Oct 26, 2013
I need an explanation of what linked lists are. How the nodes are been defined and used, especially in an object oriented programming. With a code example.
View 1 Replies
View Related
Dec 24, 2013
using the following header files:
Code:
#include <list>
#include <map>
#include <iostream>
#include <algorithm>
and
Code:
std::list
If there is a creation of a list, how can one find the sizeof the list. and is it possible to copy all the data from the linked list into an array. Assuming that the data is of type
Code:
char
View 1 Replies
View Related
Jul 6, 2013
I'm trying to run so called student-administration program.I got functions that can read and write student data, but the one saving the data from about 30 students has some problem that I can't figure. (warning: I'm quite new to C programming)so this is the code:..I guess I can't use global variables as function arguments?
Code:
//global variables
static char ReturnName[31];
static char ReturnFirstName[31];
static float ReturnAverage;
}
[code]....
incompatible types when assigning to type 'char[31]' from type 'int'
View 2 Replies
View Related
Apr 14, 2014
I'm having a problem trying to modify my patient's data. It seems to work, but once the block of code ends it does not save to the linked list.
Problem located in case M.
linked list template header: [URL] ...
patient header: [URL] ...
patient implementation: [URL] ...
#include <iostream>
#include "listTemplate.h"
#include "PatientRecord.h"
using namespace std;
char menu() {
char input
[Code]...
View 1 Replies
View Related
Mar 20, 2014
Program to implement Dijkstra's Algorithm. Have Problems storing graph info into linked-list . The input is in the following format
5
1 2 9.0
1 3 12.0
2 4 18.0
2 3 6.0
2 5 20.0
3 5 15.0
0
1 5
The first number is the number of vertexes in the graph. Then next lines up to 0 are the edges of the graph. With the first and second numbers being the vertexes and the third being how far the edge is between them. Trying to read in the data and store the edges into there locations in the List adjacency for that vertex. This example would make a graph with five vertexes with edges from 1 to 2&3. 2 to 4&3&1 etc. It also stores in the opposites ex 2 1 9.0.
When reading it in and printing it back out it seems that it is only storing the last data entered for that vertex. EX. When trying to print out the data read in i only get 1 3 12.0, 2 5 20.0, 3 5 15.0, ( 4 2 18.0, 5 3 15.0 would show up if `if(i<n)` was removed it is there so it does not show duplicate edges).
#include <cstdio>
using namespace std;
struct ListCell {
ListCell* next;
int vertex;
double weight;
ListCell(int v, double w, ListCell* nxt)
[Code] ....
View 5 Replies
View Related
Sep 28, 2013
why strcmp() doesn't return true when comparing a string constant with a string that was acquired via a linked list. By the way, the data in the linked list was taken from a text file. Does that imply that there's a new line () character in the string from the linked list?
Code:
struct Node{
char ACNO[15];
struct Node *next;
[Code]....
View 1 Replies
View Related
Aug 12, 2013
i am making a program that reads a file from .txt and print them out using linked list. However, i need to sort them from the highest price to lowest price.
Code:
/* my structs */
typedef struct{
Node *head;
Node *tail;
Node *iterator;
int size;
} List;
[Code]...
i know its long but im afraid that i might miss out some things.
View 12 Replies
View Related
May 16, 2013
Error:
--------------------Configuration: nc - Win32 Debug--------------------
Compiling...
cv.cpp
Linking...
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/nc.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
nc.exe - 2 error(s), 0 warning(s)
Compiles with 0 error but on running 2 Errors appear.
I'm Inputting data of an object from user and then inserting it in the link list.
#include <iostream>
//#include <fstream>
using namespace std;
#define LEN 100
////////////////////////////////////////////////////////////////////////////////////////////////////
class employee{
[Code] ....
View 1 Replies
View Related
Mar 30, 2014
The program use a circular linked list and data structures to store the tasks.
- Every task should include a task name, a name for the person assigned to it, and the deadline for the task.
- Variables should be dynamic and their sizes should be determined at runtime based on the length of user input.
- You should implement the following functions (with appropriate arguments and return types) for your structure: add(), remove(), search(), and list().
- The add()function should add tasks alphabetically by task name. You do not need to implement any file operations.
- The search() function should be able search for a task by the task assignee name or the task name.
- The list() function should print records to the screen in the order they appear in the circular linked list.
- You should successfully deallocate all of the allocated memory before termination of your program.
View 4 Replies
View Related
May 30, 2013
So I'm attempting to write a program that will parse through a large file (genome sequences) and I'm basically wondering what options I should consider if I wanted to either:
a) store the entire genome in memory and then parse through it
b) parse through a file in small portions
If I go with "a", should I just read a file into a vector and then parse through it? And if I go with "b" would I just use an input/output stream?
View 5 Replies
View Related
Nov 19, 2013
Code:
void loadData(fstream& fin, nodePtr head){
if (fin.eof()) {
return ;
}
else
[Code] .....
This is my function and it is not working.
View 7 Replies
View Related
Nov 17, 2013
Code:
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <iomanip>
#include "contacts.h"
using namespace std;
[Code] ....
Lines 29-32 I have a good feeling very wrong. Now I have never learned how to do this and my book covers nothing over this. I just took my final in C++ so this is not homework. I am trying to get better before Data Structures start next month.
View 3 Replies
View Related
Feb 21, 2013
I am trying to write a program which involves linked list. i have to create a method called add_aa( str ). I am reading from a text file. in the text file it just contains the values for str. what I am trying to do is create the method add_aa( str ) and add what corresponds to str from the file. here is what the output should look like. and what i have is very basic. here is what i have
inline void LList:: add_aa(const string _str) {
cout << " p = " << std::hex << p << std::dec << '
';
}
I'm thinking using a for statement, but how to incorporate it
Attached Images : sample.JPG (35.2 KB)
View 1 Replies
View Related
Oct 15, 2013
I am trying to read in a text file and add strings from it word by word into a Linked List. I'm fairly new at C and don't quite understand pointers. I've had a few different errors just messing around with it, but now I'm getting an infinite loop within my main program.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
struct listNode { /* self-referential structure */
char data[50];
struct listNode *nextPtr;
[Code] ....
When I run my full code, it prints 12345ooooooooooooooooooooooo...etc. In my test file the first word is "Hello" so that's where the infinite 'o's come from. If the outer loop is the one that is infinite, then wouldn't the second while loop also execute more than once? What I mean is, why is the second print statement the only one that repeats itself?
View 5 Replies
View Related