![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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............
|
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
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;
}
|
|
#3
|
|||
|
|||
|
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.
|
|
#4
|
||||
|
||||
|
strstr() is new for me i ever used strcmp()
|
||||
| Google The UNIX and Linux Forums |