|
-
Jul 11th, 2001, 05:04 PM
#1
Thread Starter
Hyperactive Member
errors
Code:
#include <iostream.h>
int gettxtfiles();
int main()
{
gettxtfiles();
return 0;
}
int gettxtfiles()
{
int nFiles;
cout<<"Enter the number of txt files";
cin>> nFiles;
int i;
char str[25];
char *array[100];
for(i=0;i<nFiles; i++)
{
cout <<"Enter file("<<i<< ")";
cin>>str;
array[i] = char new[strlen(str)];
array[i] = str;
cout<<array[i];
return 0;
}
In this code I get the folowing errors.
Can anyone help me out? Thanks
(26) : error C2062: type 'char' unexpected
MyProjects\checkoccurances\checkoccurances.cpp(33) : fatal error C1004: unexpected end of file found
Error executing cl.exe.
Matt 
-
Jul 11th, 2001, 05:06 PM
#2
... = new char[n];
Not
... = char new[n];
-Dennis
-
Jul 11th, 2001, 05:24 PM
#3
Thread Starter
Hyperactive Member
any idea what unexpected end of file found means?
Matt 
-
Jul 11th, 2001, 05:53 PM
#4
Monday Morning Lunatic
It means you missed off an ending brace. The compiler is expecting more code, but the file ends so it gets confused.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Jul 11th, 2001, 05:55 PM
#5
Frenzied Member
You've missed the ending brace of the int gettxtfiles() function.
-
Jul 12th, 2001, 10:12 AM
#6
Thread Starter
Hyperactive Member
thanks, i just relized the missing brace. Anyway I have one more error that I run into often and I don't get whats going on.
Code:
int oper::scan()
{
char scanstr[1000];
char strF[20];
char ch;
char temp[20];
int i;
cout<<"Enter the word you want to find";
cin>> strF;
for(i=0;i<nFiles;i++)
{
ifstream in(array[i]);
if(in.fail()){
cout<<"Error opening file";
return 1;
}
while(in.get(ch)){
strcat(scanstr,ch); //error C2664: 'strcat' : cannot convert parameter 2 from 'char' to 'const char *'
//Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
}
if(strchr(scanstr,strF)){
cout<<strF<<"found"; //error C2664: 'strchr' : cannot convert parameter 1 from 'char (*)[1000]' to 'const char *'
//Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
}
return 0;
}
}
I have the errors marked on the lines. I know I need a pointer. But why would I need it? thanks for your help!
Matt 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|