problem in connect code

This is a discussion on problem in connect code within the C Programming forums, part of the General Programming Boards category; i got problem now that i wanna do a forever loop that if user entered wrong choice it will repeat ...

  1. #16
    Registered User
    Join Date
    Dec 2008
    Posts
    183
    i got problem now that i wanna do a forever loop that if user entered wrong choice it will repeat process
    Code:
    #include <stdio.h>
    #include <windows.h>
    #include <winsock.h>
    #include <stdlib.h>//for NULL coz its macro is declared in it
    #pragma comment(lib,"wsock32.lib")
    
    void connect_ftp()
    {
    	const char *ftpname="74.50.26.15";//just test addr
    	WORD sockVersion;
    	WSADATA wsaData;
    	SOCKET badanie;//intilizing our we gonna use in connecting to ftp
    	//USE SOCKADDR_IN struct to fill in address information
    	SOCKADDR_IN sockinfo;
    	sockVersion=MAKEWORD(2,2);
    	/*NEXT WE BEGING INITLIZING WINSOCK*/
    	WSAStartup(sockVersion,&wsaData);
    	badanie=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
    	sockinfo.sin_family=AF_INET;//says we wanna use TCP/IP
    	sockinfo.sin_addr.s_addr=inet_addr(ftpname);
    	sockinfo.sin_port=htons(21);
    	if (connect(badanie,(struct sockaddr*)&sockinfo,sizeof sockinfo) == 0) { puts("Connected"); } 
    		else 
    			puts("............ YOU !!!");
    		WSACleanup();
    }
    void int_reader(char *prompt,int *num)
    {
    	fputs(prompt,stdout);
    	fflush(stdin);
    	scanf("%d",&*num);
    }
    int main(void)
    {
    	int choice;
    	char question[]="Please enter your choice of whish connector u want to";
    	char question2[]="Wrong choice please reenter";
    	puts("Menu");
    	puts("1)Ftp connector ");
    	int_reader(question,&choice);
    	for(;;)
    	{
    	switch(choice)
    	{
    	case 1: 
    		connect_ftp();break;
    	default:
    		int_reader(question2,&choice);break;
    	}
    	break;
    	}
    	return 0;
    }

  2. #17
    Registered User
    Join Date
    Dec 2008
    Posts
    183
    i can do it just exit(0); after function ended but i wanna do it within the for loop any ideas?

  3. #18
    Registered User
    Join Date
    Dec 2008
    Posts
    183
    nvm i did i needed a continue for default not break lol srry for posting 2 fast lolz

  4. #19
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300

    Arrow

    DEVELOPMENT PROCESS TIP #1:

    Get your whole program to work properly with no choices (eg, just log in to the ftp server) and then add them one at time. It's much easier, and much less prone to error.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  5. #20
    Registered User
    Join Date
    Dec 2008
    Posts
    183
    yah ur right its more easier to keep track

  6. #21
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,424
    On windows you cannot use local sockets
    What exactly do you call local sockets?
    Because I every day connect two application running on the same computer using sockets.
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  7. #22
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by vart View Post
    What exactly do you call local sockets?
    Because I every day connect two application running on the same computer using sockets.
    "Local sockets" are local sockets (type AF_LOCAL, not AF_INET). They don't deploy a tcp/ip stack. I use them to do what you are talking about, so I haven't actually tried to do IPC with AF_INET (tcp/ip) sockets. If you can, then you don't even need a LAN to fool around with -- but what addresses would you use?
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  8. #23
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,424
    Quote Originally Posted by MK27 View Post
    but what addresses would you use?
    127.0.0.1
    or
    0.0.0.0 (on the receiver)
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  9. #24
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Hmmm. I wonder if that's because there were sockets before the BSD people invented tcp/ip, which would be before windows, and so a local socket would be considered superfluous since you have all those port numbers to choose from.

    The AF_LOCAL setup is slightly simpler in that it doesn't use the sockaddr_in wrapper (the address is a local file like a pipe), so you don't have to deal with potential "network byte order" issues. Baby steps, you know.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  10. #25
    Registered User
    Join Date
    Dec 2008
    Posts
    183
    i wanted to ask whats the diff between PF_INET AND AF_INET

  11. #26
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,160
    Quote Originally Posted by lolguy View Post
    i wanted to ask whats the diff between PF_INET AND AF_INET
    Nothing.

    http://lkml.indiana.edu/hypermail/li...04.2/0091.html
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with network code
    By cornholio in forum Linux Programming
    Replies: 1
    Last Post: 12-20-2005, 12:21 AM
  2. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  3. Replies: 5
    Last Post: 09-28-2004, 12:38 PM
  4. problem with selection code
    By DavidP in forum Game Programming
    Replies: 1
    Last Post: 06-14-2004, 01:05 PM
  5. Replies: 5
    Last Post: 12-03-2003, 04:47 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21