PSP Hacks - Forums
Go Back   PSP Hacks - Forums > Tech Talk > PC Programming

Notices

Reply
 
Thread Tools Display Modes
  #1  
Old 07-15-2008, 01:25 AM
pspjoke's Avatar
pspjoke pspjoke is offline
Programmer
PSP Hacker
 
Join Date: Mar 2008
Location: U.S.
Posts: 861
pspjoke User Has a Beginner Reputation
Default

main.c
Code:
#include <iostream.h>
#include <stdio.h>
#include <stdlib.h> 

int main(void) {
FILE * pFile;
long lSize;
char * buffer;
char u;
char key[11]="ABCDEFGHIJ";


pFile = fopen ("myfile.txt" , "rb");
 
if (pFile==NULL){
   cout<<"no data in file...";
   system("pause");}
else{
     fseek (pFile , 0 , SEEK_END);
     lSize = ftell (pFile);
     rewind (pFile); 
     buffer = (char*) malloc (lSize);
//     char string[lSize]=(char*) malloc (lSize);
     if (buffer == NULL) cout<<"the buffer is null";
     fread(buffer, 1, lSize, pFile); 
//     fclose(pFile);
     cout<<"File contains: "<<buffer<<"\nsize of file is "<<lSize<<"  bytes.\n",buffer,lSize;
//     free(buffer);
     system("pause");
     char string[lSize]=buffer;
     for(int x=0; x<lSize; x++){
     string[x]=string[x]^key[x];
     printf("\nstring: %i",string);}
     system("pause");
     return 0;
}}
error
Code:
Compiler: Default compiler
Building Makefile: "D:\C++\My Prog's\Testing\Makefile.win"
Executing  make...
make.exe -f "D:\C++\My Prog's\Testing\Makefile.win" all
g++.exe -c main.cpp -o main.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include"  -I"C:/Dev-Cpp/include/c++/3.4.2/backward"  -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32"  -I"C:/Dev-Cpp/include/c++/3.4.2"  -I"C:/Dev-Cpp/include"   

In file included from C:/Dev-Cpp/include/c++/3.4.2/backward/iostream.h:31,
                 from main.cpp:1:
C:/Dev-Cpp/include/c++/3.4.2/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <iostream> instead of the deprecated header <iostream.h>. To disable this warning use -Wno-deprecated.
main.cpp: In function `int main()':

main.cpp:30: error: variable-sized object `string' may not be initialized

make.exe: *** [main.o] Error 1

Execution terminated
makefile auto generated by Dev-C++

i have tried various things to get this working, fixed some previous errors and now i can get this last one fixed.. :/
__________________
PHAT(TA-086) & GOW Slim(TA-088v2) - firmware: 5.00M33-3 - addons: 1.50 addon(phat). Me: newbie programmer...
Levone == pspjoke;
My Projects
ignorance is forgivable.. stupidity is a sin i can never forgive.
catch my latest projects at...

Reply With Quote
  #2  
Old 07-16-2008, 08:15 AM
ZiNgABuRgA's Avatar
ZiNgABuRgA ZiNgABuRgA is offline
Moderator
PSP Titan
 
Join Date: Sep 2006
Location: 4CHIN
Posts: 10,405
ZiNgABuRgA can only hope to improve
Default

Basically error says what it means - you can't declare a variable sized array.
Code:
char string[lSize]=buffer;
The variable in between the square brackets is illegal.

Use malloc() to do the job, eg:
Code:
char *string = (char*)malloc(lSize);
memcopy( ... stick something here ... );
BTW, I wouldn't consider XOR'ing much of an encryption algorithm :P
Reply With Quote
  #3  
Old 07-16-2008, 02:12 PM
pspjoke's Avatar
pspjoke pspjoke is offline
Programmer
PSP Hacker
 
Join Date: Mar 2008
Location: U.S.
Posts: 861
pspjoke User Has a Beginner Reputation
Default

yea but im new and right now thats the only one i know how to use.

btw i got this fixed in this thread http://forums.consoleworld.net/showthread.php?tid=2039.
__________________
PHAT(TA-086) & GOW Slim(TA-088v2) - firmware: 5.00M33-3 - addons: 1.50 addon(phat). Me: newbie programmer...
Levone == pspjoke;
My Projects
ignorance is forgivable.. stupidity is a sin i can never forgive.
catch my latest projects at...

Reply With Quote
Reply

 



Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -4. The time now is 09:10 PM.


Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©