473,386 Members | 1,801 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.

Locate the error

1
well i am new to this and i've got tough assignments to deal with. i worked hard on this one but my compiler shows errors. please help me

For circular function you can use a char pointer that points to the char array.
Whereas for reverse function you can copy the string stored in one array into another array reversely and displays that string.
Your output can be similar with the following:

Enter a string:
circular

String in circular order:

circular
ircularc
rcularci
cularcir
ularcirc
larcircu
arcircul
rcircula

String in reverse order:

ralucric
----------------------------------------------


#include<iostream.h>
#include<conio.h>
#include<string.h>

void circular(char[]);
void reverse(char[]);
const int size=10;

void main()
{
clrscr();
char str[size];
cout<<"Enter any word\n";
cin>>str;
cout<<"\nThe Circular of the word is :\n";
circular(str);
cout<<"\nThe Reverse of Word is : \n";
reverse(str);
getch();
}

void circular(char str[size])
{
char *sptr;
int i,j=0;

sptr=str;

while(*(sptr+1)!=0)
{
i=0;
sptr++;
j++;

cout<<sptr;

while(i<j)
{
cout<<str[i];
i++;
}

cout<<endl;
}
}

void reverse(char str[size])
{
int length = strlen(str);
for(int i=length-1; i>=0; i--)
cout<<str[i];
}
Nov 8 '06 #1
1 1227
horace1
1,510 Expert 1GB
What were the compile time errors you got?

Possible sources of errors are
(1) some compilers do not have <conio.h> which you need for clrscr() and getch()
(2) some versions of <conio.h> do not have clrscr().
(3) many modern C++ compilers requre that main() returns an int

Fixing these problems gives (which should run with any C++ compiler)
Expand|Select|Wrap|Line Numbers
  1. #include<iostream.h>
  2. //#include<conio.h>   // ** comment out
  3. #include<string.h>
  4.  
  5. void circular(char[]);
  6. void reverse(char[]);
  7. const int size=10;
  8.  
  9. int main()
  10. {
  11. //clrscr();                               // ** comment out
  12. char str[size];
  13. cout<<"Enter any word\n";
  14. cin>>str;
  15. cout<<"\nThe Circular of the word is :\n";
  16. circular(str);
  17. cout<<"\nThe Reverse of Word is : \n";
  18. reverse(str);
  19. getchar();                          // ** changed from getch()
  20. }
  21.  
  22. void circular(char str[size])
  23. {
  24. char *sptr;
  25. int i,j=0;
  26.  
  27. sptr=str;
  28.  
  29. while(*(sptr+1)!=0)
  30. {
  31. i=0;
  32. sptr++;
  33. j++;
  34.  
  35. cout<<sptr;
  36.  
  37. while(i<j)
  38. {
  39. cout<<str[i];
  40. i++;
  41. }
  42.  
  43. cout<<endl;
  44. }
  45. }
  46.  
  47. void reverse(char str[size])
  48. {
  49. int length = strlen(str);
  50. for(int i=length-1; i>=0; i--)
  51. cout<<str[i];
  52. }
  53.  
  54.  
when I now run the program I get
Enter any word circular

The Circular of the word is :
ircularc
rcularci
cularcir
ularcirc
larcircu
arcircul
rcircula

The Reverse of Word is :
ralucric
Nov 8 '06 #2

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

Similar topics

1
by: Andrew | last post by:
Dear Experts, I have a perl program that using Getopt:Std module, when I try to run the GetOpt program, the following error returned: Can’t locate Getopt.pm in @INC (@INC contains:...
0
by: packrat | last post by:
I am attempting to build a Bugzilla server on OS X. All of this is new to me, working with the Perl, MySQL, and Bugzilla, so I have been banging my head often. Software error: When I run the...
2
by: avishosh | last post by:
Hi, I'm getting the folowing error when tring to open xml file: -------------------------------------------------------------------------------- The system cannot locate the resource specified....
3
by: John Black | last post by:
Hi, In debugging a core dump, I run purify against my code, it says several "Free Memory Read" errors. All the errors are on one delete statement. Usually this means some pointer is deleted by...
0
by: sp1dEr | last post by:
Hi all, I have an asp.net application (framework 1.1 sp1) on windows server 2003. When the document root is locate in local that's all ok... but if the document root is locate on locate on...
4
by: Abubakar | last post by:
Hi, I'm using vs2k5 vc++ (native/unmanaged). I just took a separate copy of a project from source control (vss) and after fixing its dependencies build it and it builds fine. But when I try to...
0
by: SushiSean | last post by:
When executing the xmlhttp.send function to request shipper for available shipments (I send xml as string and receive result xml): XMLHTTP xmlhttp = new XMLHTTP(); xmlhttp.open("POST",...
3
by: bowser | last post by:
Hello, I'm using g++ over eclipse in a mac os x. I'm new to all these technologies. I created a dylib, and to test it I made another project that links to it, but the compiler tells me that it...
4
by: morten44 | last post by:
here the output and my Compiler version, It is a basic example from Bjarne Stroustrups homepage, morten@Westparkstr42:~/Bjarne_Stroustrup/06_Chapter_06$ g++ dc_except.c...
1
by: chaosbuddha | last post by:
Hi! I am trying to set-up mysql-zrm to take backups of a remote mysql server. The mysqlhotcopy command is throwing up the following error: Output of command: 'mysqlhotcopy' is { ...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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.