C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old March 7th, 2006, 02:47 AM
michig54 michig54 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2006
Posts: 1 michig54 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 4 m 34 sec
Reputation Power: 0
Help with C style string

My program here is suppossed to read from a file a bunch of characters using c-style strings. The File contains a paragraph with 1 word per line. I got it to read it and store it into a multi dimentional array ok, but im also suppossed to not store duplicate words. I tried and i can't figure out why what im doing isn't working. If any one could please help me that would be Great! Thanks Heres my code. . .

#include <iostream>
#include <fstream>
using namespace std;

int main()
{
fstream inputFile("input3.txt",ios::in);//open file

if (!inputFile)
{
cerr<< "File could not be opened" << endl;
exit(1);
}

char c,ary[90][12],checkary[12];
int col=0,row=0,x;

for(row=0;row<90;row++) //Nulls out every element of array
{
for(col=0;col<12;col++)
{
ary[row][col] = '\0';
}
}

for(col=0;col<12;col++) //Nulls out every element of check array
{
checkary[col] = '\0';
}

row = 0;
col = 0;
while(!inputFile.eof())//reads each character from file, then places it in array.
{
inputFile.get(c);
if( c != '\0')
{
ary[row][col]=c;
col++;
}
else
{
col=0;
row++;

for(col=0;col<12;col++)
{
checkary[col]=ary[row][col];
cout<<checkary[col];
cout<<ary[row][col];
}
//After word is stored look to see if its already there
int checkcol,checkrow;
for(checkrow=0;checkrow<86;checkrow++)
{
checkcol=0;
while((checkary[checkcol]==ary[checkrow][checkcol])||(checkary[checkcol]!='\0'))
checkcol++;
if(checkcol>=11)
{
row--;
col=0;
for(checkcol=0;checkcol<12;checkcol++)//Nulls out what was put into that row
{
ary[row][checkcol]='\0';
}
// x=0;//FALSE
break;
}
else
row++;
col = 0;
// x=0;
}//end for
}//end else
}//end while
inputFile.close();

for(row=0;row<86;row++) //Prints array
{
for(col=0;col<12;col++)
{
cout<< ary[row][col];
}
}//end print
cout<<"\n";
}//end main

Reply With Quote
  #2  
Old March 9th, 2006, 09:48 PM
lostlander lostlander is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2006
Posts: 3 lostlander User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 40 m
Reputation Power: 0
Send a message via MSN to lostlander
what do u mean by this:
inputFile.get(c);
if( c != '\0')
{
ary[row][col]=c;
col++;
}
else
{ ..... }// these codes are never executed! cos c=='\0' never succeed!

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Help with C style string


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

Request Your Free Technology Downloads!
 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

Request Your Free Technology Downloads!
 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

Request Your Free Technology Downloads!
 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

Request Your Free Technology Downloads!
 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT