Re: [Dev-C++] strcpy x pointer array
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Ioannis V. <no...@ho...> - 2003-03-07 02:36:25
|
-------Original Message-------=0D
=0D
From: Andr=E9 Mac=E1rio Barros=0D
Date: =D0=E1=F1=E1=F3=EA=E5=F5=DE, 7 =CC=DC=F1=F4=E9=EF=F2 2003 1:30:46 =F0=
=EC=0D
To: Dev-Cpp-Users=0D
Subject: [Dev-C++] strcpy x pointer array=0D
=0D
1. Please consider the following piece of code=0D
=0D
#include <stdio.h>=0D
#include <string.h>=0D
=2E..=0D
int main()=0D
{=0D
char *vect[100];=0D
=0D
=2E..=0D
/* line x */ vect[3]=3D"text";=0D
=2E..=0D
/* line y */ strcpy(vect[3], "text");=0D
=2E..=0D
}=0D
=2E..=0D
=0D
2. Both commands in lines x and y don=B4t gererate any compilation errors=
;=0D
=0D
3. The command in line x works fine;=0D
=0D
4. Why the command in line y generates an execution error interrupting th=
e=0D
execution of=0D
the program?=0D
=0D
=0D
=3D=3D> What you did is similar to:=0D
=0D
const char *p=3D"text";=0D
=0D
strcpy(p, "text");=0D
=0D
=0D
=3D=3D> After some thinking you will understand why & what it means.=0D
=0D
=0D
=0D
Ioannis Vranos=0D
=0D
* Programming pages: http://www.noicys.freeurl.com=0D
* Alternative URL: http://run.to/noicys=20 |