473,797 Members | 2,955 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

syntax error near unexpected token `('

3 New Member
Hi all
I am doing the socket programming for the client side. but the code is not compiling and i am getting the below error

./Clientsend.c: line 11: syntax error near unexpected token `('
./Clientsend.c: line 11: `int main()'

Code:
#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include <sys/types.h>

#include <sys/socket.h>

#include <netinet/in.h>

#include <arpa/inet.h>

#include <sys/types.h>

#include <sys/stat.h>

#include <unistd.h>
int main()
{

int ret, sendVal, left_bytes;

char fileName[200];

int fileReadSize = 4000;

char *buf;

int32_t i32SocketFD, i32Res;

struct sockaddr_in stSockAddr;

int fileSize;

struct stat st;

FILE* fp;


//File name input

printf("\nEnter the name of the file to be sent:\n");



scanf("%s",&fil eName);

printf("\nThe name of the file is: %s\n",fileName) ;

//Fill stat struct with file info
if(lstat (fileName, &st) != 0)
{
printf("file info attempt unsuccessful!!! ");
exit(-1);

}//end if

//Get file size and store in file size

fileSize = st.st_size;

//output file size

printf("The file Size is %d",fileSize) ;

//Open file to be read
if((fp = fopen(fileName, "r") ) == NULL)

{

printf("fopen FAILURE\n");

exit(-1);

}//end if

//Open Socket and retrieve socket descriptor

i32SocketFD = socket(PF_INET, SOCK_STREAM,0);

if(-1 == i32SocketFD)

{

printf("Cannot create socket");

exit(-1);

}//end if

//-------------------------Socket variable filling--------------------

bzero(&stSockAd dr, sizeof(stSockAd dr));



stSockAddr.sin_ family = AF_INET;

stSockAddr.sin_ port = htons(10000);

i32Res = inet_pton(AF_IN ET, "138.250.9.29", (void*)&stSockA ddr.sin_addr);





if(0 > i32Res)

{

printf("Error: First Parameter is not a valid address family");

exit(-1);

}



if(0 == i32Res)

{

printf("char string second parameter does not contain valid ipaddress");

exit(-1);

}

if(-1 == connect(i32Sock etFD,(struct sockaddr*)&stSo ckAddr,sizeof(s tSockAddr)))

{

printf("Connect ion Failed.......") ;

exit(-1);

}

//send file size to server

sendVal = send(i32SocketF D, &fileSize, sizeof(int),0);

if(sendVal == -1 )

{

printf("Invalid sending...");

exit(-1);

}

//Allocate memory to store file to be sent
buf = (char *) malloc (fileReadSize);

if (buf == NULL)

{

printf ("Malloc for buf failed");

exit (-1);

}

//set no of files left to file size so we can decreament from file size
left_bytes = fileSize;


if (fileReadSize > left_bytes) fileReadSize = left_bytes;

//Read and send file
while ((ret = fread(buf, fileReadSize, 1, fp)) >= 0)

{

int cnt = 0;



//send file take note of buf+cnt and fileReadSize-cnt

while (cnt < fileReadSize)
{

sendVal = send(i32SocketF D, buf + cnt, fileReadSize - cnt, 0);

if (sendVal < 0)
{

printf ("send eroor\n");

exit (-1);

}


//increment cnt based on send val

cnt += sendVal;

}

//reading and sending final bits of the file --- while file is coming to end

left_bytes -= fileReadSize;

if (left_bytes <= 0) break;



if (fileReadSize > left_bytes) fileReadSize = left_bytes;

printf("\nScann ing for file size...");

}//end of while loop

//----------Socket shutting and closing------------------

shutdown(i32Soc ketFD,2);

close(i32Socket FD);

fclose(fp);

return 0;

}

Please help me. i have to submit the assignment. So please help me asap

Regards
Neeraja
Mar 24 '08 #1
3 5131
Laharl
849 Recognized Expert Contributor
Please only post one thread per question. Secondly, please use the provided CODE tags when posting code.

When I c/p your code onto my computer, it compiles just fine. I'm using gcc 4.1.3 on Ubuntu and used no compilation flags other than -o.
Mar 24 '08 #2
nvr
3 New Member
Please only post one thread per question. Secondly, please use the provided CODE tags when posting code.

When I c/p your code onto my computer, it compiles just fine. I'm using gcc 4.1.3 on Ubuntu and used no compilation flags other than -o.
when i have run the program using he -o i got the following errors

please help
Clientsend.c:1: 19: error: stdio.h: No such file or directory
Clientsend.c:2: 20: error: stdlib.h: No such file or directory
Clientsend.c:3: 20: error: string.h: No such file or directory
Clientsend.c:4: 23: error: sys/types.h: No such file or directory
Clientsend.c:5: 24: error: sys/socket.h: No such file or directory
Clientsend.c:6: 24: error: netinet/in.h: No such file or directory
Clientsend.c:7: 23: error: arpa/inet.h: No such file or directory
Clientsend.c:9: 22: error: sys/stat.h: No such file or directory
Clientsend.c:10 :20: error: unistd.h: No such file or directory
Clientsend.c: In function ‘main’:
Clientsend.c:17 : error: ‘int32_t’ undeclared (first use in this function)
Clientsend.c:17 : error: (Each undeclared identifier is reported only once
Clientsend.c:17 : error: for each function it appears in.)
Clientsend.c:17 : error: expected ‘;’ before ‘i32SocketFD’
Clientsend.c:18 : error: storage size of ‘stSockAddr’ isn’t known
Clientsend.c:20 : error: storage size of ‘st’ isn’t known
Clientsend.c:21 : error: ‘FILE’ undeclared (first use in this function)
Clientsend.c:21 : error: ‘fp’ undeclared (first use in this function)
Clientsend.c:25 : warning: incompatible implicit declaration of built-in function ‘printf’
Clientsend.c:27 : warning: incompatible implicit declaration of built-in function ‘scanf’
Clientsend.c:34 : warning: incompatible implicit declaration of built-in function ‘exit’
Clientsend.c:45 : error: ‘NULL’ undeclared (first use in this function)
Clientsend.c:48 : warning: incompatible implicit declaration of built-in function ‘exit’
Clientsend.c:52 : error: ‘i32SocketFD’ undeclared (first use in this function)
Clientsend.c:52 : error: ‘PF_INET’ undeclared (first use in this function)
Clientsend.c:52 : error: ‘SOCK_STREAM’ undeclared (first use in this function)
Clientsend.c:56 : warning: incompatible implicit declaration of built-in function ‘exit’
Clientsend.c:60 : warning: incompatible implicit declaration of built-in function ‘bzero’
Clientsend.c:62 : error: ‘AF_INET’ undeclared (first use in this function)
Clientsend.c:64 : error: ‘i32Res’ undeclared (first use in this function)
Clientsend.c:70 : warning: incompatible implicit declaration of built-in function ‘exit’
Clientsend.c:76 : warning: incompatible implicit declaration of built-in function ‘exit’
Clientsend.c:81 : warning: incompatible implicit declaration of built-in function ‘exit’
Clientsend.c:89 : warning: incompatible implicit declaration of built-in function ‘exit’
Clientsend.c:93 : warning: incompatible implicit declaration of built-in function ‘malloc’
Clientsend.c:97 : warning: incompatible implicit declaration of built-in function ‘exit’
Clientsend.c:11 7: warning: incompatible implicit declaration of built-in function ‘exit’
Mar 24 '08 #3
Laharl
849 Recognized Expert Contributor
Ummm...all I can think to tell you is check in /usr/include to see if the files are actually there or not. If they're not, you might try reinstalling gcc.
Mar 24 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
5328
by: Bob Stearns | last post by:
The statement: merge into nullid.animals_et_in t1 using is3.animals t2 on t1.sire_assoc=t2.assoc and t1.sire_prefix=t2.prefix and t1.sire_regnum=t2.regnum when matched then update set t1.sire_bhid=t2.bhid when not matched then update set t1.sire_bhid=0 go gets the error message:
5
4519
by: r.nikhilk | last post by:
Hi, Currently, we are porting C++ applications from 32 bit to 64 bit on AIX platform. (The current version of AIX is 5.3 and xlC verison is 8.0). We are able to compile the applications by including the -q64 option in xlC compiler. And we are able to link all these libraries to one of the main applications and generate an executable. SKLoader. But, when we try to run this main executable, we are getting the following errors:
2
20037
by: P | last post by:
Hi all, I'm trying to run the following code taken from http://blogs.ittoolbox.com/database/technology/archives/006045.asp# select substr(tablespace_name,1,30) as "Tablespace Name", case (tablespace_type) when 0 then 'DMS' else 'SMS' end as "Type",
2
3517
by: Shrutisinha | last post by:
I am getting this error in unix .. syntax error near unexpected token `(' when i am running my parser , can anybody help me plzz .. i am new to all this thanks
3
2337
by: silambu | last post by:
hi,can anybody tell reason for getting syntax error near , while either updating or inserting records in table
4
6831
by: bhunesh | last post by:
hey , i m getting error listed below plz help me /virtualHosts/beta.myiris.com/htdocs/commodities/commd_admin/CRONJOB/new_cronjob/new_mcx.pl: line 14: syntax error near unexpected token `"/usr/bin/wget -O /tmp/mcx.dat http://www.mcxindia.com/xmlurl/GetTouchLine.aspx?userid=IRIS&pwd=CZ33M3KZ53"' #!/usr/bin/perl #Purpose : To create MCX DAT file from mcx feed coming from mcxindia.com #Author : Yatin Patil
4
3230
by: cluce | last post by:
I am getting a syntax error but I cant seem to spot it. need help with this. Its when I click the save button that fires my SQL UPDATE query. thansk in advance 'module level declarations Dim rsNames As ADODB.Recordset Dim cnDb As ADODB.Connection Dim strConnection As String Dim blnAddMode As Boolean
4
8354
by: manontheedge | last post by:
I'm using SSH Secure Shell to connect to a Linux machine ... when I try to run the compiled code I have, I keep getting these errors ... ./p2.c: line 5: syntax error near unexpected token `(' ./p2.c: line 5: `void *printMessage( void *thread_id );' here are the first few lines of the code ... #include <stdio.h>
1
2242
by: saronyo bose | last post by:
the given code does not run in linux mint isodara. on typing cc pg206(c).c in terminal it gives bash: syntax error near unexpected token `(' wat to do ........ the above code runs in windows turbo c 3.0
0
9536
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10468
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9063
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7559
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6802
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5458
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4131
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3748
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2933
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.