The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM


High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how to check string of character manas_ranjan Shell Programming and Scripting 9 05-12-2008 04:20 AM
Check for empty string rahman_riyaz Shell Programming and Scripting 12 01-24-2008 12:13 AM
read string, check string length and cut ozzy80 Shell Programming and Scripting 9 03-21-2007 02:56 PM
How to check a string in the variable josephwong Shell Programming and Scripting 1 06-25-2006 09:14 PM
How to check whether a string is number or not shihabvk Shell Programming and Scripting 8 09-21-2005 05:15 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 07-18-2007
Registered User
 

Join Date: Jul 2007
Posts: 12
how to check a closing string

i have to put in a server that if a client type in /q then server closes theconnection.......now this has to be checked in every string the client writes howto do this............
Reply With Quote
Forum Sponsor
  #2  
Old 07-19-2007
Registered User
 

Join Date: Feb 2007
Posts: 67
Though this doesn't do any networking...
Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#define MAXLINE 1000
#define QUIT "/q"

int getline(char [], int);
int string_search(char [], char []);

main()
{
	char line[MAXLINE];
	int len;

	while ((len = getline(line, MAXLINE)) > 0)
		if (strstr(line, QUIT))	/* strstr is the function you want */
			exit(0);	/* include string.h to use it */
					/* for more info on it, use google */
			
}

/* getline: read a line into s; return length */
int getline(char s[], int lim)
{
	int c, i;

	for (i=0; i<lim-1 && (c=getchar())!=EOF && c != '\n'; ++i)
		s[i] = c;
	if (c == '\n')
		s[i++] = c;
	s[i] = '\0';

	return i;
}
Reply With Quote
  #3  
Old 07-19-2007
Registered User
 

Join Date: Jan 2007
Posts: 2,965
Quote:
Originally Posted by arjunjag View Post
now this has to be checked in every string the client writes howto do this............
Make sure there is one piece of code or function that reads strings from the client and put the check in there. Either return an error condition, throw an exception or call exit() depending on the type of program.
Reply With Quote
  #4  
Old 07-22-2007
sendai's Avatar
Registered User
 

Join Date: Dec 2006
Location: Brasil
Posts: 18
strstr() is new for me i ever used strcmp()
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 12:25 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0