473,386 Members | 1,796 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Error expected unqualified -id before '{' token

2
I have an assignment that is giving me this annoying error I am wondering if anyone might know what is wrong I am by no means an expert and will take all feedback.
Feb 6 '17 #1
2 2497
Easay9
2
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <cstring>
  3. #include <cctype>
  4. #include <string.h>
  5. using std::cin;
  6. using std::cout;
  7. using std::endl;
  8.  
  9. {
  10.     strcpy(destination,source);
  11. }
  12.  
  13. {
  14.     strcpy(destination,source);
  15.  
  16.     int i=0 ,j=0;
  17.     for (i=strlen(source)-1;i>=0;i--)
  18.     {
  19.         destination[j]=source[i];
  20.         j++;
  21.     }
  22.     return destination;
  23. }
  24.  
  25. {strcpy(destination,source);
  26. int i=0, j=0;
  27. for(i=0;i<strlen(destination);i++)
  28. {
  29.     int ascval = destination[i]
  30.     if(ascval >=97 and ascval<=122) destination[i]-32;
  31. }
  32. return destination;
  33. }
  34.  
  35.  
  36. {
  37.     strcpy(destination,source);
  38.     int i=0;
  39.     for(i=0;i<strlen(destination) ;i++)
  40.     {
  41.         if (destination[i]==target) destination[i] = replace;
  42.  
  43.     }
  44.     return destination;
  45. }
  46. int main()
  47.    {
  48.    const int WORDSIZE = 15;
  49.    char words[][WORDSIZE] = {"cattywampus", "collywobbles", "Lickety Split", "Kerfuffle", "Lollygag", ""};
  50.    char word[WORDSIZE];
  51.  
  52.    // Test the copy function
  53.    cout << "Copy \"cattywampus\", should see \"cattywampus\".\n";
  54.    copy(word, words[0], sizeof(word) - 1);
  55.    cout << word << endl << endl;
  56.  
  57.    // Test the limit on the copy function
  58.    cout << "Copy \"Supercalifragilisticexpialidocious\", should see \"Super\".\n";
  59.    copy(word, "Supercalifragilisticexpialidocious", 5);
  60.    cout << word << endl << endl;
  61.  
  62.    // Test the replaceCopy function
  63.    cout << "Replace 'l' in \"collywobbles\" with 'b', should see \"cobbywobbbes\".\n";
  64.    replaceCopy(word, words[1], 'l', 'b', sizeof(word) - 1);
  65.    cout << word << endl << endl;
  66.  
  67.    // Test the limit on the replaceCopy function
  68.    cout << "Replace 's' in \"Supercalifragilistic\" with 'd', should see \"duper\".\n";
  69.    replaceCopy(word, "Supercalifragilistic", 'S', 'd', 5);
  70.    cout << word << endl << endl;
  71.  
  72.    // Test the caseChangeCopy function
  73.    cout << "Case change \"Lickety Split\", should see \"lICKETY sPLIT\".\n";
  74.    caseChangeCopy(word, words[2], sizeof(word) - 1);
  75.    cout << word << endl << endl;
  76.  
  77.    // Test the limit on the caseChangeCopy function
  78.    cout << "Case change \"Supercalifragilistic\", should see \"sUPER\".\n";
  79.    caseChangeCopy(word, "Supercalifragilistic", 5);
  80.    cout << word << endl << endl;  
  81.  
  82.    // Test the reverseCopy function
  83.    cout << "Reverse \"Kerfuffle\", should see \"elffufreK\".\n";
  84.    reverseCopy(word, words[3], sizeof(word) - 1);
  85.    cout << word << endl << endl;
  86.  
  87.    // Test the limit on the reverseCopy function
  88.    cout << "Reverse \"triskaidekaphobia\", should see \"ohpakediaksirt\".\n";
  89.    reverseCopy(word, "triskaidekaphobia", sizeof(word) - 1);;
  90.    cout << word << endl << endl;
  91.  
  92.    cout << "Reverse \"Lollygag\", change case, and replace 'G' with 'Z', should see \"ZAZYLLOl\".\n";
  93.    replaceCopy(caseChangeCopy(reverseCopy(word, words[4], sizeof(word) - 1), word, sizeof(word) - 1), word, 'G', 'Z', sizeof(word) - 1);
  94.    cout << word << endl << endl;  
  95.  
  96.    cout << "Enter your entire name: ";
  97.    read(words[5], sizeof(words[5]));
  98.    cout << words[5] << endl << endl;  
  99.  
  100.    cout << "Reverse your name and change case.\n";
  101.    cout << caseChangeCopy(reverseCopy(word, words[5], sizeof(word) - 1), word, sizeof(word) - 1) << endl;
  102.  
  103.    return 0;
  104.    }
Feb 6 '17 #2
weaknessforcats
9,208 Expert Mod 8TB
Above main() you have code that's no in a function. All code must be inside a function. You may define variables outside a function but all code instructions must be inside a function.
Feb 7 '17 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Thomas Barth | last post by:
Hi, I was wondering if someone had any insight to what I am doing wrong. I ve got a class with two methods that call static methods of another class. When compiling my sourcecodes I get the error...
21
by: Ram Prasad | last post by:
I am trying to write a simple libspf2 plugin code for my postfix ( milter) I am getting this unhelpful error message when I try to compile gcc -g1 -Wall -I/usr/local/include/spf2 -I. -c mfunc.c...
5
by: amitmool | last post by:
hi, i have used the queue library file and try to use the template as template <class QueueItem> queue <QueueItem>::~queue() // line 25 { } template <class QueueItem> void...
12
by: sam23 | last post by:
Hi all, im new to this programming language and i tried to use my Xcode to build and run this code but i got a error :(, and another error is i need a help guys #include <GLUT/glut.h>...
5
by: mahmoodn | last post by:
I have a program which uses boost 1.33.1 and it works fine with gcc 4.1 however now that I want to compile with gcc 4.4 it get many errors. For example somewhere in the boost files, it says:...
2
by: atiqah | last post by:
#include <iostream> using namespace std; class DB; class DM{ public: DM(){} DM (float meter, float cm); friend int func(DM,DB); };
17
by: AffinityCreate | last post by:
Hi, Not quite sure if someone will be able to help me but.......... I am currently trying to build a menu layout for a 20x4 LCD. I originally had the LCD working with the keypad to have a...
3
by: AffinityCreate | last post by:
Hi I am trying to add the DS1307 to my project via I2C using both a keypad and LCD. So far I have been able to get my project working with a passcode entry, led, keypad input and LCD display. I as...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.