Simple error, but how to solve?:(
-
Hi, I have a simple code but I couldn't make it run...
#include "stdafx.h" typedef int DataType; const int MAX_SIZE = 50; void merge(DataType theArray[], int first, int mid, int last); void mergesort(DataType theArray[], int first, int last) int _tmain(int argc, _TCHAR* argv[]) { int arrayToSend[4] = { 1, 2, 4, 3 }; mergesort( arrayToSend, 0, 3 ); return 0; } void merge(DataType theArray[], int first, int mid, int last) { DataType tempArray[MAX_SIZE]; // temporary array // initialize the local indexes to indicate the subarrays int first1 = first; // beginning of first subarray int last1 = mid; // end of first subarray int first2 = mid + 1; // beginning of second subarray int last2 = last; // end of second subarray // while both subarrays are not empty, copy the // smaller item into the temporary array int index = first1; // next available location in // tempArray for (; (first1 <= last1) && (first2 <= last2); ++index) { // Invariant: tempArray[first1..index-1] is in order if (theArray[first1] < theArray[first2]) { tempArray[index] = theArray[first1]; ++first1; } else { tempArray[index] = theArray[first2]; ++first2; } // end if } // end for // finish off the nonempty subarray // finish off the first subarray, if necessary for (; first1 <= last1; ++first1, ++index) // Invariant: tempArray[first1..index-1] is in order tempArray[index] = theArray[first1]; // finish off the second subarray, if necessary for (; first2 <= last2; ++first2, ++index) // Invariant: tempArray[first1..index-1] is in order tempArray[index] = theArray[first2]; // copy the result back into the original array for (index = first; index <= last; ++index) theArray[index] = tempArray[index]; } // end merge void mergesort(DataType theArray[], int first, int last) { if (first < last) { // sort each half int mid = (first + last)/2; // index of midpoint // sort left half theArray[first..mid] mergesort(theArray, first, mid); // sort right half theArray[mid+1..last] mergesort(theArray, mid+1, last); // merge the two halves merge(theArray, first, mid, last); } // end if } // end mergesort
I get errors like d:\CD\myProjects\Homeworks\hw2Q4\hw2Q4.cpp(5): warning C4518: 'int ' : storage-class or -
Hi, I have a simple code but I couldn't make it run...
#include "stdafx.h" typedef int DataType; const int MAX_SIZE = 50; void merge(DataType theArray[], int first, int mid, int last); void mergesort(DataType theArray[], int first, int last) int _tmain(int argc, _TCHAR* argv[]) { int arrayToSend[4] = { 1, 2, 4, 3 }; mergesort( arrayToSend, 0, 3 ); return 0; } void merge(DataType theArray[], int first, int mid, int last) { DataType tempArray[MAX_SIZE]; // temporary array // initialize the local indexes to indicate the subarrays int first1 = first; // beginning of first subarray int last1 = mid; // end of first subarray int first2 = mid + 1; // beginning of second subarray int last2 = last; // end of second subarray // while both subarrays are not empty, copy the // smaller item into the temporary array int index = first1; // next available location in // tempArray for (; (first1 <= last1) && (first2 <= last2); ++index) { // Invariant: tempArray[first1..index-1] is in order if (theArray[first1] < theArray[first2]) { tempArray[index] = theArray[first1]; ++first1; } else { tempArray[index] = theArray[first2]; ++first2; } // end if } // end for // finish off the nonempty subarray // finish off the first subarray, if necessary for (; first1 <= last1; ++first1, ++index) // Invariant: tempArray[first1..index-1] is in order tempArray[index] = theArray[first1]; // finish off the second subarray, if necessary for (; first2 <= last2; ++first2, ++index) // Invariant: tempArray[first1..index-1] is in order tempArray[index] = theArray[first2]; // copy the result back into the original array for (index = first; index <= last; ++index) theArray[index] = tempArray[index]; } // end merge void mergesort(DataType theArray[], int first, int last) { if (first < last) { // sort each half int mid = (first + last)/2; // index of midpoint // sort left half theArray[first..mid] mergesort(theArray, first, mid); // sort right half theArray[mid+1..last] mergesort(theArray, mid+1, last); // merge the two halves merge(theArray, first, mid, last); } // end if } // end mergesort
I get errors like d:\CD\myProjects\Homeworks\hw2Q4\hw2Q4.cpp(5): warning C4518: 'int ' : storage-class orkromozom wrote: d:\CD\myProjects\Homeworks\hw2Q4\hw2Q4.cpp(5): error C2146: syntax error : missing ';' before identifier 'main' Find your main() function declaration (or in your case _tmain(...)) Look at the line just above it. What is missing (clue is in the error message you recieved)?
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03 "Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04 Within you lies the power for good - Use it!
Honoured as one of The Most Helpful Members of 2004
-
kromozom wrote: d:\CD\myProjects\Homeworks\hw2Q4\hw2Q4.cpp(5): error C2146: syntax error : missing ';' before identifier 'main' Find your main() function declaration (or in your case _tmain(...)) Look at the line just above it. What is missing (clue is in the error message you recieved)?
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03 "Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04 Within you lies the power for good - Use it!
Honoured as one of The Most Helpful Members of 2004
Ohh my goodness, I should take a sleep. Thank you friend. I have modified the code as;
#include using namespace std; typedef int DataType; int indexOfLargest(const DataType theArray[], int size); void selectionSort(DataType theArray[], int n); void swap(DataType& x, DataType& y); int main() { return 0; } void selectionSort(DataType theArray[], int n) { for (int last = n-1; last >= 1; --last) { int largest = indexOfLargest(theArray, last+1); // Descending order. swap(theArray[largest], theArray[n - last]); } // end for } // end selectionSort int indexOfLargest(const DataType theArray[], int size) { int indexSoFar = 0; // index of largest item // found so far for (int currentIndex = 1; currentIndex < size; ++currentIndex) { // Invariant: theArray[indexSoFar] >= // theArray[0..currentIndex-1] if (theArray[currentIndex] > theArray[indexSoFar]) indexSoFar = currentIndex; } // end for return indexSoFar; // index of largest item } // end indexOfLargest void swap(DataType& x, DataType& y) { DataType temp = x; x = y; y = temp; } // end swap
But this time I get the error of d:\CD\myProjects\Homeworks\hw2Q4\hw2Q4.cpp(11): fatal error C1075: end of file found before the left brace '{' at 'd:\CD\myProjects\Homeworks\hw2Q4\hw2Q4.cpp(10)' was matched How can I solve this one? Thanks... -
Ohh my goodness, I should take a sleep. Thank you friend. I have modified the code as;
#include using namespace std; typedef int DataType; int indexOfLargest(const DataType theArray[], int size); void selectionSort(DataType theArray[], int n); void swap(DataType& x, DataType& y); int main() { return 0; } void selectionSort(DataType theArray[], int n) { for (int last = n-1; last >= 1; --last) { int largest = indexOfLargest(theArray, last+1); // Descending order. swap(theArray[largest], theArray[n - last]); } // end for } // end selectionSort int indexOfLargest(const DataType theArray[], int size) { int indexSoFar = 0; // index of largest item // found so far for (int currentIndex = 1; currentIndex < size; ++currentIndex) { // Invariant: theArray[indexSoFar] >= // theArray[0..currentIndex-1] if (theArray[currentIndex] > theArray[indexSoFar]) indexSoFar = currentIndex; } // end for return indexSoFar; // index of largest item } // end indexOfLargest void swap(DataType& x, DataType& y) { DataType temp = x; x = y; y = temp; } // end swap
But this time I get the error of d:\CD\myProjects\Homeworks\hw2Q4\hw2Q4.cpp(11): fatal error C1075: end of file found before the left brace '{' at 'd:\CD\myProjects\Homeworks\hw2Q4\hw2Q4.cpp(10)' was matched How can I solve this one? Thanks...Now your first line (#include statement) is incomplete. Barry Etter
-
Now your first line (#include statement) is incomplete. Barry Etter
-
no no, it writes
#include < iostream >
there, but editor took it as a tag. I really couldn't why this error is coming from.You need to remove blocks of code until the error goes away, then start adding them back until you identify the problem. Barry Etter
-
Ohh my goodness, I should take a sleep. Thank you friend. I have modified the code as;
#include using namespace std; typedef int DataType; int indexOfLargest(const DataType theArray[], int size); void selectionSort(DataType theArray[], int n); void swap(DataType& x, DataType& y); int main() { return 0; } void selectionSort(DataType theArray[], int n) { for (int last = n-1; last >= 1; --last) { int largest = indexOfLargest(theArray, last+1); // Descending order. swap(theArray[largest], theArray[n - last]); } // end for } // end selectionSort int indexOfLargest(const DataType theArray[], int size) { int indexSoFar = 0; // index of largest item // found so far for (int currentIndex = 1; currentIndex < size; ++currentIndex) { // Invariant: theArray[indexSoFar] >= // theArray[0..currentIndex-1] if (theArray[currentIndex] > theArray[indexSoFar]) indexSoFar = currentIndex; } // end for return indexSoFar; // index of largest item } // end indexOfLargest void swap(DataType& x, DataType& y) { DataType temp = x; x = y; y = temp; } // end swap
But this time I get the error of d:\CD\myProjects\Homeworks\hw2Q4\hw2Q4.cpp(11): fatal error C1075: end of file found before the left brace '{' at 'd:\CD\myProjects\Homeworks\hw2Q4\hw2Q4.cpp(10)' was matched How can I solve this one? Thanks...kromozom wrote: d:\CD\myProjects\Homeworks\hw2Q4\hw2Q4.cpp(11): fatal error C1075: end of file found before the left brace '{' at 'd:\CD\myProjects\Homeworks\hw2Q4\hw2Q4.cpp(10)' was matched The compiler is telling you that it could not find a closing brace '}' to match the opening brace on line 10 of your hw2Q4.cpp file.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03 "Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04 Within you lies the power for good - Use it!
Honoured as one of The Most Helpful Members of 2004
-
kromozom wrote: d:\CD\myProjects\Homeworks\hw2Q4\hw2Q4.cpp(11): fatal error C1075: end of file found before the left brace '{' at 'd:\CD\myProjects\Homeworks\hw2Q4\hw2Q4.cpp(10)' was matched The compiler is telling you that it could not find a closing brace '}' to match the opening brace on line 10 of your hw2Q4.cpp file.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03 "Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04 Within you lies the power for good - Use it!
Honoured as one of The Most Helpful Members of 2004
-
But I have friend, the all code is this. Can you take a look at it in your compiler? There is no unmatched curly bracket as far as I see. If someone can point for me I will be glad to see it?!
just insert this one as the very first line of your code: #include "stdafx.h"
-
just insert this one as the very first line of your code: #include "stdafx.h"
Thank you very much it worked. But this tme I got the errors like hw2 error LNK2019: unresolved external symbol "void __cdecl selectionSort(int * const,int)" (?selectionSort@@YAXQAHH@Z) referenced in function _main hw2 fatal error LNK1120: 1 unresolved externals