Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 132,108 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,178 people online right now. Registration is fast and FREE... Join Now!




still the same the input? why?

 
Reply to this topicStart new topic

still the same the input? why?, input doesnt work!!!

dudzken8
post 6 Oct, 2008 - 04:34 AM
Post #1


New D.I.C Head

*
Joined: 1 Oct, 2008
Posts: 12

guys a palindrome program can be limited? i mean a string? need info coz im beginner
User is offlineProfile CardPM

Go to the top of the page

Amadeus
post 6 Oct, 2008 - 04:42 AM
Post #2


g++ -o drink whiskey.cpp

Group Icon
Joined: 12 Jul, 2002
Posts: 12,168



Thanked 33 times

Dream Kudos: 25
My Contributions


Not sure what you mean by limited, but I'll go out on a limb and say....yes! Can you explain a little more? there are several palindrome testers on the site.
User is online!Profile CardPM

Go to the top of the page

dudzken8
post 6 Oct, 2008 - 04:52 AM
Post #3


New D.I.C Head

*
Joined: 1 Oct, 2008
Posts: 12

for example:

MY INPUT:
3
yehey
anamarie
maam

if i going to change the INPUT like this:
4
yehey
anamarie
maam
nissin

the output that i change will function to the program? guys need INFO,,,
User is offlineProfile CardPM

Go to the top of the page

Amadeus
post 6 Oct, 2008 - 07:12 AM
Post #4


g++ -o drink whiskey.cpp

Group Icon
Joined: 12 Jul, 2002
Posts: 12,168



Thanked 33 times

Dream Kudos: 25
My Contributions


And we need information to be able to provide you the correct response. Are you asking if the the program can be designed in such a way that you will (or the user will specify) the number of words that may be entered?
User is online!Profile CardPM

Go to the top of the page

dudzken8
post 7 Oct, 2008 - 12:29 AM
Post #5


New D.I.C Head

*
Joined: 1 Oct, 2008
Posts: 12

yah i mean the number of words,,guys the program will fuction if the number is "change and so on"? coz many times ill change the INPUT and it happen nothing its function the program palindrome? guys need info,,,
User is offlineProfile CardPM

Go to the top of the page

dudzken8
post 7 Oct, 2008 - 01:04 AM
Post #6


New D.I.C Head

*
Joined: 1 Oct, 2008
Posts: 12

CODE
#include <string.h>
#include <stdio.h>
#include <iostream.h>

FILE *input, *output;
char myStr[100], myTmp[100];
int iden=1, index=0;

void main()
{
  input = fopen("c:/Project/p1.in.txt","r");
  output = fopen("c:/Project/p1.out.txt","w");

  if (input == NULL)
  {
    cout << "Error opening the file!\n\n";
  }

  else
  {
    while (!feof(input))
    {
      char getChar = fgetc(input);

      if (getChar != '\n')
      {
        if (iden != 1)
        {
            myStr[index] = getChar;
            index++;
        }
      }
      else
      {
        if (iden != 1)
        {
            myStr[index] = NULL;
            index=0;
            strcpy(myTmp,myStr);
            strrev(myTmp);
    
            if (strcmp(myTmp,myStr) == 0)
            {
                cout << myStr << "  -  TRUE\n";
                fwrite("TRUE\n",5,1,output);
            }
            else
            {
                cout << myStr << "  -  FALSE\n";     
                fwrite("FALSE\n",6,1,output);
            }
        }
        iden++;
     }
    }
    fclose(input);
    fclose(output);
  }
}
User is offlineProfile CardPM

Go to the top of the page

dudzken8
post 7 Oct, 2008 - 01:15 AM
Post #7


New D.I.C Head

*
Joined: 1 Oct, 2008
Posts: 12

guys the INPUT in this program is:
3
yehey
anamarie
no devil lived

if i will change to the INPUT like this:
4
yehey
anamarie
no devil lived on
maam

guys the INPUT that i will change is will function this program? coz many times that i wll change the INPUT still the same the INPUT :
3
yehey
anamarie
no devil lived on

guys need INFo about this?
User is offlineProfile CardPM

Go to the top of the page

dudzken8
post 7 Oct, 2008 - 03:20 AM
Post #8


New D.I.C Head

*
Joined: 1 Oct, 2008
Posts: 12

cpp
#include <string.h>
#include <stdio.h>
#include <iostream.h>

FILE *input, *output;
char myStr[100], myTmp[100];
int iden=1, index=0;

void main()
{
input = fopen("c:/Project/p1.in.txt","r");
output = fopen("c:/Project/p1.out.txt","w");

if (input == NULL)
{
cout << "Error opening the file!\n\n";
}

else
{
while (!feof(input))
{
char getChar = fgetc(input);

if (getChar != '\n')
{
if (iden != 1)
{
myStr[index] = getChar;
index++;
}
}
else
{
if (iden != 1)
{
myStr[index] = NULL;
index=0;
strcpy(myTmp,myStr);
strrev(myTmp);

if (strcmp(myTmp,myStr) == 0)
{
cout << myStr << " - TRUE\n";
fwrite("TRUE\n",5,1,output);
}
else
{
cout << myStr << " - FALSE\n";
fwrite("FALSE\n",6,1,output);
}
}
iden++;
}
}
fclose(input);
fclose(output);
}
}


guys the INPUT in this program is:
3
yehey
anamarie
no devil lived

if i will change to the INPUT like this:
4
yehey
anamarie
no devil lived on
maam

guys the INPUT that i will change is will function this program? coz many times that i wll change the INPUT still the same the INPUT :
3
yehey
anamarie
no devil lived on

guys need INFo about this?

MOD EDIT: Please code.gif
Thanks, gabehabe smile.gif
User is offlineProfile CardPM

Go to the top of the page

gabehabe
post 7 Oct, 2008 - 03:22 AM
Post #9


Working Girl.

Group Icon
Joined: 6 Feb, 2008
Posts: 5,402



Thanked 94 times

Dream Kudos: 2625

Expert In: Dingleberries

My Contributions


Don't double post. Threads merged.

Why are you using C file I/O and C++ console I/O?

Don't mix the two. Use <fstream>
User is offlineProfile CardPM

Go to the top of the page

UG Cyber
post 7 Oct, 2008 - 01:04 PM
Post #10


D.I.C Head

**
Joined: 24 Jul, 2008
Posts: 184



Thanked 3 times
My Contributions


guy, use fstream like this
cpp

#include <fstream>
using namespace std;

int main(void)
{
ofstream fout; //output file stream
ifstream fin; //input filestream
fout.open("FileName.txt", ios::app) //So it keeps it current contents

fout << "Use like you are using cout<<" << endl;
fin.getline(Buffer, sizeof(Buffer)); //use like cin>>
}



p.s. Double post is bad enough, but TRIPLE crazy.gif
User is offlineProfile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 11/21/08 09:38AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month