GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 30-Mar-2009, 12:23
dinh0wjr dinh0wjr is offline
New Member
 
Join Date: Mar 2009
Location: Salvador, Bahia, Brazil
Posts: 2
dinh0wjr is on a distinguished road

Expected primary-expression before '.' token


Well, First of all, Sorry if i'm repeating a question asked before, cause i've seen a topic simillar to mine, but i couldn't understand what was explained there.

I'm new here, and read the 'rules', so i'll just give a brief information bout myself:
I'm Dinho, and work with Coldfusion, i'm learning C for my college.

Now let's go to what matters:
i'm getting an "expected primary-expression before '.' token" error when i try to compile the following code:

CPP / C++ / C Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct listaEncadeada {
    char                    valGuardado[30];
    struct listaEncadeada   *proxLista;
};

typedef listaEncadeada *Lista;

int main(int argc, char *argv[]) {
    strcpy(Lista.valGuardado,"AAAA");
    scanf( "%s", &Lista.valGuardado );
    printf("\nValor Digitado = %s\n",Lista.valGuardado);
    system("PAUSE");
    return 0;

}

Regards,
Dinho
  #2  
Old 30-Mar-2009, 12:39
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 5,218
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: expected primary-expression before '.' token


Quote:
Originally Posted by dinh0wjr
i'm getting an "expected primary-expression before '.' token" error

First of all, I think you need to declare a variable whose type is the struct that you defined, not make a typedef. Maybe something like:
CPP / C++ / C Code:
#include <stdio.h>
#include <string.h>

struct listaEncadeada {
    char                    valGuardado[30];
    struct listaEncadeada   *proxLista;
};


int main()
{
    struct listaEncadeada Lista;

    strcpy(Lista.valGuardado,"AAAA");
    printf("\nValor Digitado = %s\n",Lista.valGuardado);

    return 0;
}
Output:

Code:
Valor Digitado = AAAA

Now, if you want to make a typedef for the struct (to simplify the variable declaration), you could try something like:
CPP / C++ / C Code:
#include <stdio.h>
#include <string.h>

struct listaEncadeada {
    char                    valGuardado[30];
    struct listaEncadeada   *proxLista;
};

typedef struct listaEncadeada ListaStruct;

int main()
{
    ListaStruct Lista;

    strcpy(Lista.valGuardado,"AAAA");
    printf("\nValor Digitado = %s\n",Lista.valGuardado);

    return 0;
}

Same output as before.

Regards,

Dave
  #3  
Old 30-Mar-2009, 13:13
dinh0wjr dinh0wjr is offline
New Member
 
Join Date: Mar 2009
Location: Salvador, Bahia, Brazil
Posts: 2
dinh0wjr is on a distinguished road

Re: expected primary-expression before '.' token


Works perfectly!
TY, Dave!
 
 

Recent GIDBlogProblems with the Navy (Chiefs) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
main.cpp:15: error: expected primary-expression before ',' token DingbatCA C++ Forum 8 29-Oct-2007 13:52
Error: expected unqualified-id before ‘{’ token ftmthy412 C++ Forum 5 12-Sep-2007 17:49
Converting PHP to C and I need a little help Allenport C Programming Language 4 14-Aug-2006 14:38
error: expected primary-expression before '.' token Honourable Mist C++ Forum 11 18-Feb-2006 13:15
Help with syntax errors PeteGallo C Programming Language 7 08-Aug-2005 21:30

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 20:53.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.