![]() |
|
#1
|
||||
|
||||
|
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;
}}
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
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... |
|
#2
|
||||
|
||||
|
Basically error says what it means - you can't declare a variable sized array.
Code:
char string[lSize]=buffer; Use malloc() to do the job, eg: Code:
char *string = (char*)malloc(lSize); memcopy( ... stick something here ... ); |
|
#3
|
||||
|
||||
|
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... |
![]() |
|
|
|||
|
|||
|
|
| Thread Tools | |
| Display Modes | |
|
|