Parse error before string constant?

This is a discussion on Parse error before string constant? within the C++ Programming forums, part of the General Programming Boards category; Hi I am incredibly new to C++ programming and am sure my code is an absolute mess: Code: #include <iostream> ...

  1. #1
    Registered User
    Join Date
    May 2009
    Posts
    2

    Parse error before string constant?

    Hi I am incredibly new to C++ programming and am sure my code is an absolute mess:
    Code:
    #include <iostream>
    #include <stdlib.h>
    struct listNode {
    	int value;
    	struct listNode *next;
    	};
    typedef struct listNode LISTNODE;
    LISTNODE *createList(void);
    LISTNODE *addNodeAfter(LISTNODE *list, int node);
    LISTNODE *getNextNode(LISTNODE *thisNode);
    int setNodeValue(LISTNODE *list, int node, int value);
    int getNodeValue(LISTNODE *list, int node, int *value);
    main()
    {
    	LISTNODE *listStart=0;
    	int nodeValue, count;
    	listStart=createList();
    	if (listStart == 0) {
    		cout << "Failed create the list !\n";
    		}
    	cout << "Created linked list starting at : " << listStart "\n";
    	if (!setNodeValue(listStart, 0, 1234)) {
    		cout << "Failed to set the first node value !\n";
    		}
    	if (!getNodeValue(listStart, 0, &nodeValue)) {
    		cout << "Failed to get the first node value !\n";
    		}
    	cout << "The first node has a value of: " << nodeValue "\n";
    	if (!addNodeAfter(listStart, 0)) {
    		cout << "Failed to create new node !\n";
    		}
    	if (!setNodeValue(listStart, 1, 5678)) {
    		cout << "Failed to set the second node value !\n";
    		}
    	if (!getNodeValue(listStart, 1, &nodeValue)) {
    		cout << "Failed to get the second node value !\n";
    		}
    	cout << "The second node has a value of: " << nodeValue "\n";
    	for (count=2; count<100; count++) {
    		if (!addNodeAfter(listStart, count-1)) {
    			cout << "Failed to create node %i !\n",count+1;
    			break;
    			}
    		setNodeValue(listStart, count, 11*count);
    		}
    	getNodeValue(listStart, count/2, &nodeValue);
    	cout << "Node " << count/2 "has value: " << nodeValue "\n";
    	return 0;
    	}
    LISTNODE *createList(void)
    {
    	LISTNODE *newList;
    	newList=(LISTNODE *)malloc(sizeof(LISTNODE));
    	if (newList != NULL) {
    		newList->value=0;
    		newList->next=0;
    		}
    	return newList;
    	}
    LISTNODE *addNodeAfter(LISTNODE *list, int node)
    {
    	int count=0;
    	LISTNODE *thisNode, *nextNode, *newNode;
    	thisNode=list;
    	newNode=(LISTNODE *)malloc(sizeof(LISTNODE));
    	if (newNode == NULL) {
    		return NULL;
    		}
    	newNode->value=0;
    	while (thisNode != 0) {
    		if (count == node) {
    			nextNode=getNextNode(thisNode);
    			newNode->next=nextNode;
    			thisNode->next=newNode;
    			return newNode;
    			}
    		count++;
    		thisNode=getNextNode(thisNode);
    		}
    	return NULL;
    	}
    LISTNODE *getNextNode(LISTNODE *thisNode)
    {
    	return thisNode->next;
    	}
    int setNodeValue(LISTNODE *list, int node, int value)
    {
    	int count=0;
    	LISTNODE *thisNode;
    	thisNode=list;
    	while (thisNode != 0) {
    		if (count == node) {
    			thisNode->value=value;
    			return 1;
    			}
    		count++;
    		thisNode=getNextNode(thisNode);
    		}
    	return 0;
    	}
    int getNodeValue(LISTNODE *list, int node, int *value)
    {
    	int count=0;
    	LISTNODE *thisNode;
    	thisNode=list;
    	while (thisNode != 0) {
    		if (count == node) {
    			*value=thisNode->value;
    			return 1;
    			}
    		count++;
    		thisNode=getNextNode(thisNode);
    		}
    	return 0;
    	}
    I tried compiling and it said I had a "parse error before string constant" error on the lines that are in red.

  2. #2
    Banned ಠ_ಠ's Avatar
    Join Date
    Mar 2009
    Posts
    687
    you didn't put a << before "\n"
    ╔╗╔══╦╗
    ║║║╔╗║║
    ║╚╣╚╝║╚╗
    ╚═╩══╩═╝

  3. #3
    Registered User
    Join Date
    May 2009
    Posts
    2
    Thank you very much, I've been staring at it for ages...

    edit: I've been asked to try overloading the > operator so I can compare 2 linkedList objects and use this to implement a sort() method in the linkedList class that puts the items in ascending order of value. I'm sure there is a simple way of doing this but that sounds like a foreign language to me. Is there a short and simple way of going about this. Any help would be greatly appreciated.
    Last edited by skev21; 05-05-2009 at 08:41 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ ini file reader problems
    By guitarist809 in forum C++ Programming
    Replies: 7
    Last Post: 09-04-2008, 06:02 AM
  2. RicBot
    By John_ in forum C++ Programming
    Replies: 8
    Last Post: 06-13-2006, 06:52 PM
  3. Parse Error Before String Constant?
    By xombie in forum C Programming
    Replies: 4
    Last Post: 10-08-2004, 01:17 AM
  4. Linked List Help
    By CJ7Mudrover in forum C Programming
    Replies: 9
    Last Post: 03-10-2004, 09:33 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21