9 Replies - 662 Views - Last Post: 07 October 2008 - 02:04 PM Rate Topic: -----

#1 dudzken8  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 01-October 08

still the same the input? why?

Post icon  Posted 06 October 2008 - 05:34 AM

guys a palindrome program can be limited? i mean a string? need info coz im beginner
Is This A Good Question/Topic? 0
  • +

Replies To: still the same the input? why?

#2 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: still the same the input? why?

Posted 06 October 2008 - 05:42 AM

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.
Was This Post Helpful? 0
  • +
  • -

#3 dudzken8  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 01-October 08

Re: still the same the input? why?

Posted 06 October 2008 - 05:52 AM

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,,,
Was This Post Helpful? 0
  • +
  • -

#4 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: still the same the input? why?

Posted 06 October 2008 - 08:12 AM

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?
Was This Post Helpful? 0
  • +
  • -

#5 dudzken8  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 01-October 08

Re: still the same the input? why?

Posted 07 October 2008 - 01:29 AM

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,,,
Was This Post Helpful? 0
  • +
  • -

#6 dudzken8  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 01-October 08

Re: still the same the input? why?

Posted 07 October 2008 - 02:04 AM

#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);
  }
}

Was This Post Helpful? 0
  • +
  • -

#7 dudzken8  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 01-October 08

Re: still the same the input? why?

Posted 07 October 2008 - 02:15 AM

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?
Was This Post Helpful? 0
  • +
  • -

#8 dudzken8  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 01-October 08

Re: still the same the input? why?

Post icon  Posted 07 October 2008 - 04:20 AM

#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:
Thanks, gabehabe :)
Was This Post Helpful? 0
  • +
  • -

#9 gabehabe  Icon User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1376
  • View blog
  • Posts: 10,951
  • Joined: 06-February 08

Re: still the same the input? why?

Posted 07 October 2008 - 04:22 AM

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>
Was This Post Helpful? 0
  • +
  • -

#10 UG Cyber  Icon User is offline

  • D.I.C Addict

Reputation: 32
  • View blog
  • Posts: 546
  • Joined: 24-July 08

Re: still the same the input? why?

Posted 07 October 2008 - 02:04 PM

guy, use fstream like this
#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:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1