how to check a closing string


 
Thread Tools Search this Thread
Top Forums Programming how to check a closing string
# 1  
Old 07-18-2007
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............
# 2  
Old 07-19-2007
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  
Old 07-20-2007
Quote:
Originally Posted by arjunjag
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.
# 4  
Old 07-22-2007
strstr() is new for me i ever used strcmp()
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep: check if a string comes up twice

I have the following files list.txt string1<TAB>ABC string2<TAB>DEF string3<TAB>GHIquery.txt ABC DEF GHI ABCNow I want to check, if a string in the first column of list.txt is twice in query.txt so my command is: while IFS=$'\t' read k v ; do if (($(grep -i '$v' query.txt | wc... (2 Replies)
Discussion started by: tons92
2 Replies

2. Shell Programming and Scripting

Cant check empty string

Hello So i have that script collection, in which i have a single script to create a configuration file. In there, i have multiple occourences of something like this: prj_title=$(tui-read "What is the TITLE? ($prj_name):") ] && prj_title="${prj_name/_/ }" They all work as expected, if... (5 Replies)
Discussion started by: sea
5 Replies

3. Shell Programming and Scripting

Check for rows with particular string

Hi. The data file is as below: 2000922111111100232091212098324.... 2123011230912832094820943684896.... 3435983453409583405938453049583.... . . . I need to get only the rows that match my criteria. For example: those at characters 5-10 should equal to "922111" (thus getting only the 1st... (7 Replies)
Discussion started by: daytripper1021
7 Replies

4. Shell Programming and Scripting

Check if the string is empty

I am reading from a file and executing the jobs with/without parameters as the job requires. File job1 R job2 job3 Y 123 if then <job>.ksh else <job>.ksh $params fi This works fine if the line read from the file has parameters it executes like job1.ksh R But for... (2 Replies)
Discussion started by: nw2unx123
2 Replies

5. Shell Programming and Scripting

Check file for string existence before appending it with string

I want to append file with a string but before doing that i want to check if this string already exist in that file.I tried with grep on Solaris 10 but unsuccessful.Man pages from grep seems to suggest if the string is found command status will be 0 and if not 1.But i am not finding it.May be i... (2 Replies)
Discussion started by: sahil_shine
2 Replies

6. Shell Programming and Scripting

How to check string encoding?

I want to check if the string is WINDOWS-1251 or UTF-8 can you help me to find the string encoding??? or maybe to get URL Content-Type charset with wget? this is my function on PHP function check_utf8($str) { $len = strlen($str); for($i = 0; $i < $len; $i++){ $c =... (2 Replies)
Discussion started by: sanantonio7777
2 Replies

7. Shell Programming and Scripting

check if one string comes before another

I want to search a file to check if there is string a before string b: string a, b might not necessarily be in the file, and to return a boolean string a (any text) string b i have tried for an hour to do this with perl, grep, etc. but no luck grep doesnt search for patterns... (7 Replies)
Discussion started by: vanessafan99
7 Replies

8. Shell Programming and Scripting

read string, check string length and cut

Hello All, Plz help me with: I have a csv file with data separated by ',' and optionally enclosed by "". I want to check each of these values to see if they exceed the specified string length, and if they do I want to cut just that value to the max length allowed and keep the csv format as it... (9 Replies)
Discussion started by: ozzy80
9 Replies

9. UNIX for Dummies Questions & Answers

to check if a string has only digits

Hi guys, I am not very experienced in writing ksh scripts and I am trying to write a piece of code that indicates if a given string contains only digits and no alphabet (upper or lower case). If i write it my way it would turn out to have a lot of comparisons.. :eek: Thanks a lot in... (3 Replies)
Discussion started by: lakshmikanth
3 Replies
Login or Register to Ask a Question