Results 1 to 6 of 6

Thread: errors

  1. #1

    Thread Starter
    Hyperactive Member MPrestonf12's Avatar
    Join Date
    Jun 1999
    Location
    NY
    Posts
    330

    Angry 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

  2. #2
    denniswrenn
    Guest
    ... = new char[n];

    Not

    ... = char new[n];


    -Dennis

  3. #3

    Thread Starter
    Hyperactive Member MPrestonf12's Avatar
    Join Date
    Jun 1999
    Location
    NY
    Posts
    330
    any idea what unexpected end of file found means?
    Matt

  4. #4
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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

  5. #5
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    You've missed the ending brace of the int gettxtfiles() function.
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  6. #6

    Thread Starter
    Hyperactive Member MPrestonf12's Avatar
    Join Date
    Jun 1999
    Location
    NY
    Posts
    330
    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
  •  



Click Here to Expand Forum to Full Width