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 -
#include<iostream>
-
#include<cstring>
-
#include<fstream>
-
int reverse(char* str);
-
using namespace std;
-
-
int main()
-
{
-
ifstream infile;
-
ofstream outfile;
-
infile.open("input.txt");
-
outfile.open("output.txt");
-
char name[60];
-
char invname[60];
-
-
if(infile.fail())
-
cout<<"FAILED";
-
else
-
{
-
while(!infile.eof())
-
{
-
infile.getline(name,'\n');
-
reverse(name);
-
}
-
}
-
return 0;
-
}
-
-
-
int Reverse(char* str)
-
{
-
if (NULL==str)return -1; //no string
-
int l=strlen(str)-1; //get the string length
-
if (1==l)return 1;
-
-
for(int x=0;x < l;x++,l--)
-
{
-
str[x]^=str[l]; //triple XOR Trick
-
str[l]^=str[x]; //for not using a temp
-
str[x]^=str[l];
-
}
-
return 0;
-
}
-
-
the error is -
Linking...
-
asdqwe.obj : error LNK2001: unresolved external symbol "int __cdecl reverse(char *)" (?reverse@@YAHPAD@Z)
-
Debug/asdqwe.exe : fatal error LNK1120: 1 unresolved externals
-
Error executing link.exe.
-
-
asdqwe.exe - 2 error(s), 0 warning(s)
-
can enyone explain the error for me please and tell what to do......ASAP please!!!!!!
7 2447
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 -
#include<iostream>
-
#include<cstring>
-
#include<fstream>
-
int reverse(char* str);
-
using namespace std;
-
-
int main()
-
{
-
ifstream infile;
-
ofstream outfile;
-
infile.open("input.txt");
-
outfile.open("output.txt");
-
char name[60];
-
char invname[60];
-
-
if(infile.fail())
-
cout<<"FAILED";
-
else
-
{
-
while(!infile.eof())
-
{
-
infile.getline(name,'\n');
-
reverse(name);
-
}
-
}
-
return 0;
-
}
-
-
-
int Reverse(char* str)
-
{
-
if (NULL==str)return -1; //no string
-
int l=strlen(str)-1; //get the string length
-
if (1==l)return 1;
-
-
for(int x=0;x < l;x++,l--)
-
{
-
str[x]^=str[l]; //triple XOR Trick
-
str[l]^=str[x]; //for not using a temp
-
str[x]^=str[l];
-
}
-
return 0;
-
}
-
-
the error is -
Linking...
-
asdqwe.obj : error LNK2001: unresolved external symbol "int __cdecl reverse(char *)" (?reverse@@YAHPAD@Z)
-
Debug/asdqwe.exe : fatal error LNK1120: 1 unresolved externals
-
Error executing link.exe.
-
-
asdqwe.exe - 2 error(s), 0 warning(s)
-
can enyone explain the error for me please and tell what to do......ASAP please!!!!!!
declare function after using namespace std;
declare function after using namespace std;
Done that
made no differance
enything else?
ok i got it i revised the code to -
#include<iostream>
-
#include<cstring>
-
#include<fstream>
-
void reverseit(char array[]);
-
using namespace std;
-
int main()
-
{
-
ifstream infile;
-
-
infile.open("input.txt");
-
outfile.open("output.txt");
-
char name[60];
-
-
-
if(infile.fail())
-
cout<<"FAILED";
-
else
-
{
-
while(!infile.eof())
-
{
-
infile.getline(name,60);
-
reverseit(name);
-
-
}
-
}
-
return 0;
-
}
-
-
-
-
-
void reverseit(char array[])
-
{
-
char c; int len, mid=0;
-
-
len = strlen(array);
-
mid = (len-1)/2;
-
-
for(int i=0,j=len-1; i <=mid; i++,j--)
-
{ c = array[i];
-
array[i] = array[j];
-
array[j] = c;
-
}
-
cout <<array<<endl;
-
}
-
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
Laharl 849
Recognized Expert Contributor
You can simply ignore the character if it fails a isalpha() test. isalpha can be found in <cctype>.
ok i will try that
anyone knows whats wrong with this func -
void copy(char array[],char copyarray[])
-
{
-
strcpy(copyarray,array);
-
int i=0;
-
char c;
-
-
while (copyarray[i])
-
{
-
c=copyarray[i];
-
putchar (toupper(c));
-
i++;
-
}
-
}
-
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????
I can see the putchar so that explains LIKE. Now what are you doing after this functon returns?? Maybe displaying the original array??
ok i will try that
anyone knows whats wrong with this func -
void copy(char array[],char copyarray[])
-
{
-
strcpy(copyarray,array);
-
int i=0;
-
char c;
-
-
while (copyarray[i])
-
{
-
c=copyarray[i];
-
putchar (toupper(c));
-
i++;
-
}
-
}
-
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.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Ying Yang |
last post by:
Hi,
whats the difference between:
char* a = new char;
char* b = new char;
char c ;
|
by: truedos |
last post by:
hello,
I have a text file that looks like this:
text
numbers
text
numbers
text
numbers
..
..
|
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.
|
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;
|
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
| |
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()
|
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
|
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?
|
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
|
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...
|
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,...
| |
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...
|
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...
|
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...
|
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();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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...
| |