LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-25-2004, 05:45 PM   #1
Longinus
Member
 
Registered: Sep 2003
Distribution: Redhat 9.0 && Slackware 9.1
Posts: 420

Rep: Reputation: 30
Question what is wrong with this pointer thingy


hi

i am new to pointers and i am having some trouble with this:

----------------------------------------------------
#include <iostream>
using namespace std;

typedef struct{
char alpha[26];
short num;
}MyStruct;

int main(){

MyStruct ms1;
MyStruct *pms1 = &ms1;

pms1->alpha = "abcdefghijklmnopqrstuvwxyz";
pms1->num = 5;


cout << "The memory address of num is: " << &(pms1->num) << endl;
cout<< "num is: " << pms1->num << endl;

return 0;
}
------------------------------------------------------

the error appears o nline 14 according to g++:

--------------------------------------------------
pointers7.cc: In function `int main()':
pointers7.cc:14: incompatible types in assignment of `const char[27]' to `
char[26]'
-----------------------------------------------

if anybody could tell me whats wrong that would be awesome

thanks
 
Old 02-25-2004, 06:13 PM   #2
ToniT
Senior Member
 
Registered: Oct 2003
Location: Zurich, Switzerland
Distribution: Debian/unstable
Posts: 1,357

Rep: Reputation: 47
Your array is too sort, you have forgotten the null character.

Also you can't do array assignments this in C++, only in C. Use one of: strcpy (see man strcpy), char pointer instead of statically 27 characters or C++/STL string class

BTW: when pasting code and referring to line numbers, please pipe it through nl.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
returning data to main() via a pointer to a pointer. slzckboy Programming 3 05-30-2005 01:20 PM
Getting there TAR.GZ thingy jymmi Linux - Newbie 9 03-30-2005 10:16 AM
hot to set value of pointer to pointer to a structure in C alix123 Programming 2 11-17-2004 06:40 AM
wrong mouse pointer in transparent terminals seth_m Linux - General 6 10-27-2003 03:06 PM
< thingy nero64 Linux - Newbie 1 11-28-2002 07:39 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:22 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration