473,654 Members | 3,107 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problrm in invesing a char array

64 New Member
i have this code which suppose to get a n input from the file and store it in a char array then i have to inverse it.....
rhis code isnt complete but im getting a wiered error
i see the error when the c++ starts linking not in the compilation procces.
my code is
Expand|Select|Wrap|Line Numbers
  1. #include<iostream>
  2. #include<cstring>
  3. #include<fstream>
  4. int reverse(char* str);
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. ifstream infile;
  10. ofstream outfile;
  11. infile.open("input.txt");
  12. outfile.open("output.txt");
  13. char name[60];
  14. char invname[60];
  15.  
  16.     if(infile.fail())
  17.     cout<<"FAILED";
  18.     else
  19.     {
  20.     while(!infile.eof())
  21.     {
  22.                infile.getline(name,'\n');
  23.                  reverse(name);
  24. }
  25. }
  26. return 0;
  27. }    
  28.  
  29.  
  30. int Reverse(char* str)
  31. {
  32. if (NULL==str)return -1; //no string
  33. int l=strlen(str)-1; //get the string length
  34. if (1==l)return 1;
  35.  
  36. for(int x=0;x < l;x++,l--)
  37. {
  38. str[x]^=str[l];  //triple XOR Trick
  39. str[l]^=str[x];  //for not using a temp
  40. str[x]^=str[l];
  41. }
  42. return 0;
  43. }
  44.  
  45.  
the error is
Expand|Select|Wrap|Line Numbers
  1. Linking...
  2. asdqwe.obj : error LNK2001: unresolved external symbol "int __cdecl reverse(char *)" (?reverse@@YAHPAD@Z)
  3. Debug/asdqwe.exe : fatal error LNK1120: 1 unresolved externals
  4. Error executing link.exe.
  5.  
  6. asdqwe.exe - 2 error(s), 0 warning(s)
  7.  
can enyone explain the error for me please and tell what to do......ASAP please!!!!!!
Dec 14 '07 #1
7 2447
mschenkelberg
44 New Member
i have this code which suppose to get a n input from the file and store it in a char array then i have to inverse it.....
rhis code isnt complete but im getting a wiered error
i see the error when the c++ starts linking not in the compilation procces.
my code is
Expand|Select|Wrap|Line Numbers
  1. #include<iostream>
  2. #include<cstring>
  3. #include<fstream>
  4. int reverse(char* str);
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. ifstream infile;
  10. ofstream outfile;
  11. infile.open("input.txt");
  12. outfile.open("output.txt");
  13. char name[60];
  14. char invname[60];
  15.  
  16.     if(infile.fail())
  17.     cout<<"FAILED";
  18.     else
  19.     {
  20.     while(!infile.eof())
  21.     {
  22.                infile.getline(name,'\n');
  23.                  reverse(name);
  24. }
  25. }
  26. return 0;
  27. }    
  28.  
  29.  
  30. int Reverse(char* str)
  31. {
  32. if (NULL==str)return -1; //no string
  33. int l=strlen(str)-1; //get the string length
  34. if (1==l)return 1;
  35.  
  36. for(int x=0;x < l;x++,l--)
  37. {
  38. str[x]^=str[l];  //triple XOR Trick
  39. str[l]^=str[x];  //for not using a temp
  40. str[x]^=str[l];
  41. }
  42. return 0;
  43. }
  44.  
  45.  
the error is
Expand|Select|Wrap|Line Numbers
  1. Linking...
  2. asdqwe.obj : error LNK2001: unresolved external symbol "int __cdecl reverse(char *)" (?reverse@@YAHPAD@Z)
  3. Debug/asdqwe.exe : fatal error LNK1120: 1 unresolved externals
  4. Error executing link.exe.
  5.  
  6. asdqwe.exe - 2 error(s), 0 warning(s)
  7.  
can enyone explain the error for me please and tell what to do......ASAP please!!!!!!


declare function after using namespace std;
Dec 14 '07 #2
Alenik1989
64 New Member
declare function after using namespace std;
Done that
made no differance
enything else?
Dec 14 '07 #3
Alenik1989
64 New Member
ok i got it i revised the code to
Expand|Select|Wrap|Line Numbers
  1. #include<iostream>
  2. #include<cstring>
  3. #include<fstream>
  4. void reverseit(char array[]);
  5. using namespace std;
  6. int main()
  7. {
  8.     ifstream infile;
  9.  
  10.     infile.open("input.txt");
  11.         outfile.open("output.txt");
  12.         char name[60];
  13.  
  14.  
  15.         if(infile.fail())
  16.             cout<<"FAILED";
  17.         else
  18.         {
  19.             while(!infile.eof())
  20.             {
  21. infile.getline(name,60);
  22. reverseit(name);
  23.  
  24.             }
  25.             }
  26.         return 0;
  27. }    
  28.  
  29.  
  30.  
  31.  
  32. void reverseit(char array[])
  33.     char c; int len, mid=0;
  34.  
  35.     len = strlen(array); 
  36.     mid = (len-1)/2;
  37.  
  38.     for(int i=0,j=len-1; i <=mid; i++,j--)
  39.     { c = array[i];
  40.       array[i] = array[j];
  41.       array[j] = c;
  42.     }
  43.     cout <<array<<endl;
  44. }
  45.  
this is working perfect but i have another problem
this code suppose to determine if the input is palindrome (original and reversed have to be the same)!!!!
programs works perfectly for words like MADAM but not for phrases like
madam, i'm adam
which it reversed is mada m'i ,madam if you ignore the spaces and punctuation while comparing it will read like madamimmadam and the original would be madamimadam...

my question is how can i ignore the punctuation and spaces when copmaring the original and reversed arrays? (can i use strcmp)!!!
TANX
Dec 14 '07 #4
Laharl
849 Recognized Expert Contributor
You can simply ignore the character if it fails a isalpha() test. isalpha can be found in <cctype>.
Dec 14 '07 #5
Alenik1989
64 New Member
ok i will try that
anyone knows whats wrong with this func
Expand|Select|Wrap|Line Numbers
  1. void copy(char array[],char copyarray[])
  2. {
  3.     strcpy(copyarray,array);
  4.     int i=0;
  5.   char c;
  6.  
  7.   while (copyarray[i])
  8.   {
  9.     c=copyarray[i];
  10.     putchar (toupper(c));
  11.     i++;
  12.   }
  13. }
  14.  
it suppose to get the array and make all of its contents to upper charachters!!!!
but it repeats the original one after the upper one like when array=like
copyarray is shown as LIKElike

any ideas????
Dec 15 '07 #6
weaknessforcats
9,208 Recognized Expert Moderator Expert
I can see the putchar so that explains LIKE. Now what are you doing after this functon returns?? Maybe displaying the original array??
Dec 16 '07 #7
happyjack27
4 New Member
ok i will try that
anyone knows whats wrong with this func
Expand|Select|Wrap|Line Numbers
  1. void copy(char array[],char copyarray[])
  2. {
  3.     strcpy(copyarray,array);
  4.     int i=0;
  5.   char c;
  6.  
  7.   while (copyarray[i])
  8.   {
  9.     c=copyarray[i];
  10.     putchar (toupper(c));
  11.     i++;
  12.   }
  13. }
  14.  
it suppose to get the array and make all of its contents to upper charachters!!!!
but it repeats the original one after the upper one like when array=like
copyarray is shown as LIKElike

any ideas????

you're making the problem overly complicated. you don't need to use strcpy or putchar. just write one character at a time to the destination array: the upper case version of the corresponding character in the source array. you want to set each character in the destination array to be the upper case version of the corresponding character in the source array, right? so write that.
Dec 16 '07 #8

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

Similar topics

35
20939
by: Ying Yang | last post by:
Hi, whats the difference between: char* a = new char; char* b = new char; char c ;
7
1636
by: truedos | last post by:
hello, I have a text file that looks like this: text numbers text numbers text numbers .. ..
21
18856
by: Bret | last post by:
I'm curious why char** argv is acceptable in the main() declaration. In the comp.lang.c FAQ (question 6.18) it says that pointers to pointers and pointers to an array are not interchangable. However the declaration: int main(int argc, char** argv) is common.
19
14509
by: gaga | last post by:
I can't seem to get this to work: #include <stdio.h> #include <stdlib.h> #include <string.h> int main() { char *names; char **np;
5
3962
by: jab3 | last post by:
(again :)) Hello everyone. I'll ask this even at risk of being accused of not researching adequately. My question (before longer reasoning) is: How does declaring (or defining, whatever) a variable **var make it an array of pointers? I realize that 'char **var' is a pointer to a pointer of type char (I hope). And I realize that with var, var is actually a memory address (or at
12
5502
by: arkobose | last post by:
my earlier post titled: "How to input strings of any lengths into arrays of type: char *array ?" seems to have created a confusion. therefore i paraphrase my problem below. consider the following program: #include<stdio.h> #define SIZE 1 int main()
13
2112
by: chellappa | last post by:
hi , please explain me , char pointer , char Array, char ,string... i have some many confussion about this... please clarify to me.. i need some example about this program by chellappa.ns
15
34583
by: Kueishiong Tu | last post by:
How do I convert a Byte array (unsigned char managed) to a char array(unmanaged) with wide character taken into account?
3
3487
by: ZMan | last post by:
The following code won't compile with gcc version 3.4.2 (mingw-special). How come? Error: cannot convert `char (*)' to `char**' /**********************************************************/ #include <cstdio> #define MAX_WORD_LEN 80 #define MAX_SIZE 1000
0
8375
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8290
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8815
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8707
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7306
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5622
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4149
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4294
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1593
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.