My compile points to this as the first error in my function. I am confused why it wouldn't like the malloc. All other errors seem to follow because of this.
The error is as follows:
error: no match for ‘operator=’ in ‘headCurrent = (Node*)malloc(24ul)’
This is the first error on line 48, and I can only assume right now all other errors follow because of this.
Thanks for the help.
#include <stdlib.h>
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
struct Node {
char eastVal;
char southVal;
Node* east;
Node* south;
};
void buildManhattanGrid(Node* head, ifstream eastFile, ifstream southFile);
int main() {
Node* head;
ifstream eastFile, southFile;
eastFile.open("eastFile.txt", ifstream::in);
southFile.open("southFile.txt", ifstream::in);
buildManhattanGrid(head, eastFile, southFile);
return 0;
}
void buildManhattanGrid(Node* head, ifstream eastFile, ifstream southFile) {
string eastStr, southStr;
Node* headPrev, headCurrent, tailCurrent, temp, tailPrev;
while(!eastFile.eof()) {
getline(eastFile, eastStr);
getline(southFile, southStr);
if(headPrev != NULL) {
//Create the head of each list at coordinate(0,Y)
headCurrent = (Node*)malloc(sizeof(struct Node));
headCurrent->eastVal = eastStr.at(0);
headCurrent->southVal = southStr.at(0);
tailCurrent = headCurrent;
headPrev->south = headCurrent;
for(int i = 2; i < eastStr.length(); i+2) {
temp = (Node*)malloc(sizeof(struct Node));
temp->eastVal = eastStr.at(i);
temp->southVal = southStr.at(i);
tailCurrent->east = temp;
tailCurrent = temp;
headPrev = headPrev->east;
headPrev->south = temp;
}
headPrev = headCurrent;
} else {
headPrev = (Node*)malloc(sizeof(struct Node));
headPrev->east = eastStr.at(0);
headPrev->south = southStr.at(0);
tailPrev = headPrev;
for(int i = 2; i < eastStr.length(); i+2) {
temp = (Node*)malloc(sizeof(struct Node));
temp->eastVal = eastStr.at(i);
temp->southVal = southStr.at(i);
tailPrev->east = temp;
tailPrev = temp;
}
}
}
}


Sign In
Create Account


Back to top









