473,472 Members | 2,264 Online
Bytes | Software Development & Data Engineering Community
Create 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",&fileName);

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(&stSockAddr, sizeof(stSockAddr));



stSockAddr.sin_family = AF_INET;

stSockAddr.sin_port = htons(10000);

i32Res = inet_pton(AF_INET, "138.250.9.29",(void*)&stSockAddr.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(i32SocketFD,(struct sockaddr*)&stSockAddr,sizeof(stSockAddr)))

{

printf("Connection Failed.......");

exit(-1);

}

//send file size to server

sendVal = send(i32SocketFD, &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(i32SocketFD, 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("\nScanning for file size...");

}//end of while loop

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

shutdown(i32SocketFD,2);

close(i32SocketFD);

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 5100
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:117: 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
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...
5
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...
2
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...
2
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
by: silambu | last post by:
hi,can anybody tell reason for getting syntax error near , while either updating or inserting records in table
4
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...
4
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...
4
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 `('...
1
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
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...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.