need help finding problems

This is a discussion on need help finding problems within the C++ Programming forums, part of the General Programming Boards category; need help with finding problems with this code Code: #include<stdio.h> #pragma once #include<fstream.h> #pragma once int createnew( char u[12], char ...

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    44

    need help finding problems

    need help with finding problems with this code
    Code:
    #include<stdio.h>
    #pragma once
    #include<fstream.h>
    #pragma once
    
    
    
    
    
    
    int createnew( char u[12], char p[12] );
    int check( char u[12], char p[12] );
    
    
    main(int argc, char *argv[]){
    	/* argv[0] mode argv[1] user argv[2] password*/
    	char user[]=argv[1];
    char password[]=argv[2];	
    	
    	
    	if( argv[0] == 'n'){
    		createnew( user , password );
    	}
    
    	else if( argv[0] == 'c'){
    		check( user , password );
    	}
    
    	return 0;
    }
    
    
    check( char u[12] , char p[12] ){
    	FILE *fp;
    	char password[12];
        char filename[16] = u[];
    	strcat(filename,".txt");
    	fp=fopen(filename, "rb");
    	if(p == fp){
    		printf("true");
    	return 0;
    	}
    
    	else if(p != fp){
    		printf("false");
    	return 0;
    	}
    }
    
    
    
    
    	
    
    
    
    
    
    
    createnew( char u[12] , char p[12] ){
    	char filename[16] = u[];
    	strcat(filename,".txt");
    	ofstream datafile(filename, ios::binary);
    	datafile.write( (char *) &p, sizeof p);
    }
    here is the warnings the compiler gives me

    Compiling...
    login.c
    C:\Programs\login\login\login.c(17) : error C2075: 'user' : array initialization needs curly braces
    C:\Programs\login\login\login.c(18) : error C2075: 'password' : array initialization needs curly braces
    C:\Programs\login\login\login.c(21) : warning C4047: '==' : 'char *' differs in levels of indirection from 'const int '
    C:\Programs\login\login\login.c(25) : warning C4047: '==' : 'char *' differs in levels of indirection from 'const int '
    C:\Programs\login\login\login.c(36) : error C2059: syntax error : ']'
    C:\Programs\login\login\login.c(37) : warning C4013: 'strcat' undefined; assuming extern returning int
    C:\Programs\login\login\login.c(39) : warning C4133: '==' : incompatible types - from 'struct _iobuf *' to 'char *'
    C:\Programs\login\login\login.c(44) : warning C4133: '!=' : incompatible types - from 'struct _iobuf *' to 'char *'
    C:\Programs\login\login\login.c(61) : error C2059: syntax error : ']'
    C:\Programs\login\login\login.c(63) : error C2065: 'ofstream' : undeclared identifier
    C:\Programs\login\login\login.c(63) : error C2146: syntax error : missing ';' before identifier 'datafile'
    C:\Programs\login\login\login.c(63) : warning C4013: 'datafile' undefined; assuming extern returning int
    C:\Programs\login\login\login.c(63) : error C2065: 'ios' : undeclared identifier
    C:\Programs\login\login\login.c(63) : error C2143: syntax error : missing ')' before ':'
    C:\Programs\login\login\login.c(63) : error C2059: syntax error : ')'
    C:\Programs\login\login\login.c(64) : error C2224: left of '.write' must have struct/union type
    Error executing cl.exe.
    Location:SASKATOON,SASKATCHWAN,CANADA
    Operating System:Microsoft Windows XP sp1
    Compilers:Gnu gcc-2.96, Microsoft Visual C++ 6.0

  2. #2
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    C:\Programs\login\login\login.c(17) : error C2075: 'user' : array initialization needs curly braces
    C:\Programs\login\login\login.c(18) : error C2075: 'password' : array initialization needs curly braces
    You can't assign the CL parameters like that. If you're going to have arrays without specifying the number of elements, you need to declare them dynamically, and you can't use the = to assing strings, unless you overload it. You need to set up a couple of for loops and do the assignment on a char by char basis.

    C:\Programs\login\login\login.c(21) : warning C4047: '==' : 'char *' differs in levels of indirection from 'const int '
    C:\Programs\login\login\login.c(25) : warning C4047: '==' : 'char *' differs in levels of indirection from 'const int '
    You should be dereferencing the pointers before using then like that.

    C:\Programs\login\login\login.c(36) : error C2059: syntax error : ']'
    Again, you can't assign arrays like that.

    C:\Programs\login\login\login.c(37) : warning C4013: 'strcat' undefined; assuming extern returning int
    You need to include the header for that

    C:\Programs\login\login\login.c(39) : warning C4133: '==' : incompatible types - from 'struct _iobuf *' to 'char *'
    C:\Programs\login\login\login.c(44) : warning C4133: '!=' : incompatible types - from 'struct _iobuf *' to 'char *'
    You just need to be more careful with your data types. You need to either typecast or learn more about the API to do everything manually. I would recommend the latter.

    C:\Programs\login\login\login.c(61) : error C2059: syntax error : ']'
    You've seen this before

    C:\Programs\login\login\login.c(63) : error C2065: 'ofstream' : undeclared identifier
    Once again, you need to include the header for this class

    C:\Programs\login\login\login.c(63) : error C2146: syntax error : missing ';' before identifier 'datafile'
    You're missing the ';'

    C:\Programs\login\login\login.c(63) : warning C4013: 'datafile' undefined; assuming extern returning int
    This is just a side effect of all your other errors and the fact that they are causing other lines of code not to execute

    C:\Programs\login\login\login.c(63) : error C2065: 'ios' : undeclared identifier
    Header files again

    C:\Programs\login\login\login.c(63) : error C2143: syntax error : missing ')' before ':'
    C:\Programs\login\login\login.c(63) : error C2059: syntax error : ')'
    You just need to look for typos

    C:\Programs\login\login\login.c(64) : error C2224: left of '.write' must have
    struct/union type

    Another side effect

    How to Debug

    The compiler will always tell you the type of error (syntax, etc...), the line number on which it occurs (the number in parentheses), a description of the error that occurred, and a unique number that identifies the error. By looking at the line number and descriptions you should be able to see a problem in your code. If not, you need to look at the documentation for your compiler and find the error ID numbers - there you will find a more detailed description of what went wrong and maybe even a suggestion of how to fix it.
    Last edited by sean; 08-22-2004 at 05:53 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Tips for finding scope problems
    By stanlvw in forum C++ Programming
    Replies: 6
    Last Post: 04-14-2009, 10:26 PM
  2. MFC :: Finding Child Window of a CWnd* Object?
    By SyntaxBubble in forum Windows Programming
    Replies: 2
    Last Post: 09-06-2003, 09:06 AM
  3. Common Problems
    By WolfPack in forum C Programming
    Replies: 4
    Last Post: 01-28-2003, 05:38 PM
  4. tile colliision detection problems
    By werdy666 in forum Game Programming
    Replies: 1
    Last Post: 10-23-2002, 09:26 PM
  5. Coding Problems
    By RpiMatty in forum C++ Programming
    Replies: 12
    Last Post: 01-06-2002, 01:47 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21