[error] .cpp expected primary-expression before '.' token

I received this error when I want to compile.It's from function'extract'
anyone know how to fix it? :(

.cpp expected primary-expression before '.' token


this is my code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159

  
#include<iostream>
#include<fstream>
#include<cstdlib>
#include<string>

using namespace std;
struct shipInfo
{
       string shipDate;
       int PartNo;
       string TrackingNo;
       string FName;
       string LName;
       string Company;
};

const int numrecs = 5;
void writeFile();
void sortDesc(shipInfo ship[]);
void extract (shipInfo ship[]);

int main()
{
    writeFile();
      
    
 


   system("pause");
   return 0;
}

void writeFile()
{
	shipInfo ship[numrecs] = {{"12/01/2014",50625,"C74444","Robo","Cop","SeePlusPlus"},
                               {"31/01/2014",60752,"X75255","Power","Rangers","Whatsup"},
                               {"10/02/2014",40295,"G74477","Kiki","Lalat","Bingo&Co"},
                               {"15/03/2014",23745,"A71232","Cicak","Man","LizardoLtd"},
                               {"12/01/2014",70892,"M76321","Miki","Maus","CarToon"}};
	int i;
	
    string filename="shipping.txt";
    ofstream outfile;
    
    outfile.open(filename.c_str());
    
    if(outfile.fail())
    {
                      cout<<"The file was not successfully open "<<endl;
                      exit(1);
    }
    
    for(i=0;i<numrecs;i++)
	{
	outfile<<ship[i].shipDate<<" ";
	outfile<<ship[i].PartNo<<" ";
    outfile<<ship[i].TrackingNo<<" ";
    outfile<<ship[i].FName<<" ";
	outfile<<ship[i].LName<<" ";
	outfile<<ship[i].Company<<" ";
	outfile<<endl;
    }
    
    outfile.close();
    cout<<"The file has been written"<<endl;
    sortDesc(ship);
    extract(ship); 
    
    
    return ;
}
void sortDesc(shipInfo ship[])
{
	string file1name = "sortShipping.txt", temp;         //fx sortdesc tp wt dlm fx lg
	ofstream outfile ;	
	int temp2 ;
    outfile.open(file1name.c_str()) ;
    
   for(int x=0 ;x<4; x++)
   {
           for(int y=1 ; y<5 ; y++)
           {
                   
           if(ship[y].LName < ship[y-1].LName)
           {
                  temp = ship[y].shipDate ;
                  ship[y].shipDate = ship[y-1].shipDate ;
                  ship[y-1].shipDate = temp ;   
                  
                  temp2 = ship[y].PartNo ;
                  ship[y].PartNo = ship[y-1].PartNo ; 
                  ship[y-1].PartNo = temp2 ;
                  
                  temp = ship[y].TrackingNo ;     
                  ship[y].TrackingNo = ship[y-1].TrackingNo ;
                  ship[y-1].TrackingNo =temp ; 
                  
                  temp = ship[y].FName ;
                  ship[y].FName = ship[y-1].FName ;
                  ship[y-1].FName = temp ;
                  
                  temp = ship[y].LName ;
                  ship[y].LName = ship[y-1].LName ;
                  ship[y-1].LName = temp ; 
                  
                  temp = ship[y].Company ;
                  ship[y].Company = ship[y-1].Company ;
                  ship[y-1].Company = temp ;
           }
                  
                  
           }
           
           
   }
   
    string filename="sortShipping.txt";
    ofstream secfile;
    
    secfile.open(filename.c_str());
    
    if(secfile.fail())
    {
                      cout<<"The file was not successfully open "<<endl;
                      exit(1);
    }
    
    for(int i=0;i<numrecs;i++)
	{
	secfile<<ship[i].shipDate<<" ";
	secfile<<ship[i].PartNo<<" ";
    secfile<<ship[i].TrackingNo<<" ";
    secfile<<ship[i].FName<<" ";
	secfile<<ship[i].LName<<" ";
	secfile<<ship[i].Company<<" ";
	secfile<<endl;
    }
    
    secfile.close();
    cout<<"The file has been written successfully."<<endl <<endl;
   
    system("cls");
   
   return;
   
}

void extract(shipInfo ship[])
{
   
    cout << shipInfo.LName << endl;
    
    return;
}
     
For shipInfo.LName to compile shipInfo need to be an object but in your code it's a class.
 
shipInfo //name a class 


You must access to LName, from ship []
thanks everyone :D

fixed

1
2
3
4
5
6
7
8
9
void extract(shipInfo ship[])
{
    for(int i=0;i<numrecs;i++)
    cout << ship[i].LName << endl;
    
    
 
}
   
Topic archived. No new replies allowed.