473,395 Members | 1,763 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

string copy problem

kk
I wanna initialize a 3D character string array with a string "abc" but the
above VC 6.0++ compiler failed to do so.

what's the problem of the below codes and how to modify it?
char interface_aanum[10][100][4];

for (int k=0; k<10; k++)
for (int i=0; i<100; i++)
strcpy(interface_aanum[k][i], "abc");

error C2107: illegal index, indirection not allowed
error C2664: 'strcpy' : cannot convert parameter 1 from 'char (*)[4]' to
'char *'
Types pointed to are unrelated; conversion requires
reinterpret_cast, C-style cast or function-style cast

Nov 14 '05 #1
2 4064
On Mon, 11 Oct 2004 09:49:07 +0800, "kk" <kk******@cuhk.edu.hk> wrote
in comp.lang.c:
I wanna initialize a 3D character string array with a string "abc" but the
above VC 6.0++ compiler failed to do so.

what's the problem of the below codes and how to modify it?
char interface_aanum[10][100][4];

for (int k=0; k<10; k++)
for (int i=0; i<100; i++)
strcpy(interface_aanum[k][i], "abc");

error C2107: illegal index, indirection not allowed
error C2664: 'strcpy' : cannot convert parameter 1 from 'char (*)[4]' to
'char *'
Types pointed to are unrelated; conversion requires
reinterpret_cast, C-style cast or function-style cast


The error message above indicates that you are compiling this code as
C++, not C. Try news:comp.lang.c++.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Nov 14 '05 #2
kk wrote:
I wanna initialize a 3D character string array with a string "abc" but the
above VC 6.0++ compiler failed to do so.

what's the problem of the below codes and how to modify it?
char interface_aanum[10][100][4];

for (int k=0; k<10; k++)
for (int i=0; i<100; i++)
strcpy(interface_aanum[k][i], "abc");
This code should work (on a C99 compiler), but for most C compilers
(C89|C90 compliant) something like
#include <string.h>

int main(void)
{
char interface_aanum[10][100][4];
int k, i;
for (k = 0; k < 10; k++)
for (i = 0; i < 100; i++)
strcpy(interface_aanum[k][i], "abc");

return 0;
}

is necessary. But your error messages
error C2107: illegal index, indirection not allowed
error C2664: 'strcpy' : cannot convert parameter 1 from 'char (*)[4]' to
'char *'
Types pointed to are unrelated; conversion requires
reinterpret_cast, C-style cast or function-style cast


indicate that you are not compiling this as C code, since the
diagnostics make no sense unless issued by a C++ compiler. C++ is not
C, but a different language. It is address in the newsgroup
news:comp.lang.c++

Nov 14 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Gandalf | last post by:
Hello. I thought that strlen was only available after adding #include <string> to my c++ program, but apperently not, or the compiler is clever enough to find it by it self, or what? The...
4
by: Simon Schaap | last post by:
Hello, I have encountered a strange problem and I hope you can help me to understand it. What I want to do is to pass an array of chars to a function that will split it up (on every location where...
4
by: Locusta | last post by:
Hello, I have been struggeling for replacing a string in a string. The snippet from the program below replaces the <, & and > with the XML equivalent values. In the program, I allocate space...
19
by: Paul | last post by:
hi, there, for example, char *mystr="##this is##a examp#le"; I want to replace all the "##" in mystr with "****". How can I do this? I checked all the string functions in C, but did not...
32
by: Tubs | last post by:
Am i missing something or does the .Net Framework have a quirk in the way methods work on an object. In C++ MFC, if i have a CString and i use the format method, i format the string i am using. ...
6
by: MackS | last post by:
Hello everyone I am faced with the following problem. For the first time I've asked myself "might this actually be easier to code in C rather than in python?", and I am not looking at device...
4
by: Gaijinco | last post by:
I made this function which given two strings c1 and c2 test if with the letters of both you can exactly form the string c3, so for exaple c1 = "evol" c2= "ution" and c3 = "evolution" will yield...
5
by: Martin Jørgensen | last post by:
Hello again, Sorry to bother but I guess my C++ book isn't very good since it obviously contains errors so the program code doesn't work with g++. However I don't understand what the problem...
87
by: Robert Seacord | last post by:
The SEI has published CMU/SEI-2006-TR-006 "Specifications for Managed Strings" and released a "proof-of-concept" implementation of the managed string library. The specification, source code for...
7
by: dragoncoder | last post by:
Hello experts, I have the following code me. =cat mystring.h #include<iostream> using namespace std; class mystring {
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.