Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Simple error, but how to solve?:(

Simple error, but how to solve?:(

Scheduled Pinned Locked Moved C / C++ / MFC
c++databasedata-structureshelptutorial
10 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sacoskun
    wrote on last edited by
    #1

    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

    PJ ArendsP 1 Reply Last reply
    0
    • S sacoskun

      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

      PJ ArendsP Offline
      PJ ArendsP Offline
      PJ Arends
      wrote on last edited by
      #2

      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

      Within you lies the power for good; Use it!

      S 1 Reply Last reply
      0
      • PJ ArendsP PJ Arends

        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

        S Offline
        S Offline
        sacoskun
        wrote on last edited by
        #3

        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...

        B PJ ArendsP 2 Replies Last reply
        0
        • S sacoskun

          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...

          B Offline
          B Offline
          Barry Etter
          wrote on last edited by
          #4

          Now your first line (#include statement) is incomplete. Barry Etter

          S 1 Reply Last reply
          0
          • B Barry Etter

            Now your first line (#include statement) is incomplete. Barry Etter

            S Offline
            S Offline
            sacoskun
            wrote on last edited by
            #5

            no no, it writes #include < iostream > there, but editor took it as a tag. I really couldn't why this error is coming from.

            B 1 Reply Last reply
            0
            • S sacoskun

              no no, it writes #include < iostream > there, but editor took it as a tag. I really couldn't why this error is coming from.

              B Offline
              B Offline
              Barry Etter
              wrote on last edited by
              #6

              You need to remove blocks of code until the error goes away, then start adding them back until you identify the problem. Barry Etter

              1 Reply Last reply
              0
              • S sacoskun

                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...

                PJ ArendsP Offline
                PJ ArendsP Offline
                PJ Arends
                wrote on last edited by
                #7

                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

                Within you lies the power for good; Use it!

                S 1 Reply Last reply
                0
                • PJ ArendsP PJ Arends

                  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

                  S Offline
                  S Offline
                  sacoskun
                  wrote on last edited by
                  #8

                  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?!

                  S 1 Reply Last reply
                  0
                  • S sacoskun

                    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?!

                    S Offline
                    S Offline
                    Serge Krynine
                    wrote on last edited by
                    #9

                    just insert this one as the very first line of your code: #include "stdafx.h"

                    S 1 Reply Last reply
                    0
                    • S Serge Krynine

                      just insert this one as the very first line of your code: #include "stdafx.h"

                      S Offline
                      S Offline
                      sacoskun
                      wrote on last edited by
                      #10

                      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

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups