Review your favorite Linux distribution.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


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

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


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;

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++:

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

if anybody could tell me whats wrong that would be awesome

Old 02-25-2004, 06:13 PM   #2
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.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

All times are GMT -5. The time now is 12:15 PM.

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