等到\ n出现在字符串中 [英] wait until \n appears in string
问题描述
怎样才能检查字符串中是否出现\ n
处理\ n之前的数据和然后叠加下面的
数据,直到另一个\ n出现?
我需要这个用于套接字来知道数据的时间
已完成
示例
收到的数据=
login\\\
robert\\ \\ n n
下一个收到的数据
ns \ n
它将成为
登录 - 这将被处理,以便变量可以回收
罗伯特 - ''''
男士 - '' ''
我真的没有办法做这样的事情...
我已经习惯了视觉基本我可以用的地方循环,
但我似乎无法找到一个函数复制'的一部分
字符串,从a点到b点
仅从头到尾b
谁能帮帮我???
提前致谢,
Robert
-
ln [dot] tenalp [at] snem_trebor
读取反转并填写点& at发送电子邮件
Hi,
how is it possible to check if an \n appears in a string to
process the data before the \n and then stack up the following
data until another \n appears?
I need this for something with sockets to know when the data
is complete
example
recieved data =
login\nrobert\nme
next recieved data
ns\n
that it''ll become
login -- this will be processed so the variable can be recycled
robert -- ''''
mens -- ''''
I really don''t have a clue to do something like this...
I am used to visual basic where i could use a loop,
but i can''t seem to find a function which copy''s a part
of a string, from point a to point b
only from start to point b
Can anyone help me???
Thanks in advance,
Robert
--
ln[dot]tenalp[at]snem_trebor
read reversed and fill dot&at for email
推荐答案
Robert Mens< ro ********* @ hotmail.com>写道:
Robert Mens <ro*********@hotmail.com> wrote:
怎样才能检查字符串中是否出现\ n以便在\ n之前处理数据然后叠加以下内容
数据直到另一个\ n出现?
我需要这个带套接字的东西才能知道数据何时完成
Hi, how is it possible to check if an \n appears in a string to
process the data before the \n and then stack up the following
data until another \n appears?
I need this for something with sockets to know when the data
is complete
标准C中没有套接字,这是这里讨论的唯一主题。
标准C定义fgets(),它从文件指针读取行。在Unix
中,您可以使用fdopen(3)将套接字读入文件指针。也许在Win32中有一个等价的
。你应该在Win32新闻组上发布这个问题。
如果你实际上在使用Unix,请查看comp.unix.programmer。
- Bill
There are no sockets in Standard C, which is the sole topic discussed here.
Standard C defines fgets(), which reads lines from a file pointer. In Unix
you can finagle a socket into a file pointer using fdopen(3). Maybe there''s
an equivalent in Win32. You should post this question on a Win32 newsgroup.
If you are in fact using Unix, checkout comp.unix.programmer.
- Bill
读取:
如何检查字符串中是否出现\ n
处理\ n之前的数据,然后叠加以下
数据直到另一个\ n出现?
how is it possible to check if an \n appears in a string to
process the data before the \n and then stack up the following
data until another \n appears?
听起来像fgets的工作。
-
a签名
sounds like a job for fgets.
--
a signature
Robert Mens写道:
Robert Mens wrote:
如何检查字符串中是否出现\ n来处理数据在\ n之前然后叠加以下
数据,直到出现另一个\ n?
我需要这个用于套接字来知道数据何时完成
示例
收到的数据=
登录\ nrobert \ nn
下一个收到的数据
ns \
它会变成
登录 - 这会被处理以便变量可以被回收
罗伯特 - ''''
男士 - ''''
我真的没有办法做某事像这样...
我已经习惯了基本的视觉基础,
但是我似乎无法找到一个复制字符串部分的函数,从a点到b点
Hi,
how is it possible to check if an \n appears in a string to
process the data before the \n and then stack up the following
data until another \n appears?
I need this for something with sockets to know when the data
is complete
example
recieved data =
login\nrobert\nme
next recieved data
ns\n
that it''ll become
login -- this will be processed so the variable can be recycled
robert -- ''''
mens -- ''''
I really don''t have a clue to do something like this...
I am used to visual basic where i could use a loop,
but i can''t seem to find a function which copy''s a part
of a string, from point a to point b
如果您收到的数据是您所描述的严格格式,那么您可以写一个b $ b函数将使用函数sscanf
来解析两个数据包(字符串)。
#include< stdio.h>
#include< string.h>
typedef char string [30];
int ParseUser(const string str1,const string str2 ,字符串用户,
string passwd);
int main(无效)
{
string string1,stri ng2,用户,密码;
strcpy(string1," login\\\
robert\\\
me");
strcpy(string2," \ nns");
if(ParseUser(string1,string2,user,password))
printf(" User:%s \\\
Password:%s \ n" ;,用户,密码);
else puts(" ERROR ....");
strcpy(string1," login \ nrwashington\\\
secret");
if(ParseUser(string1,NULL,user,password))
printf(" \ nUser:%s \ nPassword: %s \ n",用户,密码);
else puts(" ERROR ....");
返回0;
}
int ParseUser(const string str1,const string str2,string user,
string passwd)
{
string tmp;
if(str1)
{
if(2!= sscanf (str1,"%* s \ n%29s \ n%29s",user,passwd))
返回0;
其他
if(str2)
{
if(1!= sscanf(str2, " \ n%29s",tmp))
返回0;
其他
{
strncat (passwd,tmp,30-strlen(tmp));
passwd [29] =''\ 0'';
}
}
}
返回1;
}
-
Al Bowers
美国佛罗里达州坦帕市
mailto: xa ****** @ myrapidsys.com (删除x以发送电子邮件)
http ://www.geocities.com/abowers822/
If your received data is a rigid format as you described, you
may be able to write a function that will use function sscanf
to parse the two packets (strings).
#include <stdio.h>
#include <string.h>
typedef char string[30];
int ParseUser(const string str1, const string str2, string user,
string passwd);
int main(void)
{
string string1, string2, user,password;
strcpy(string1,"login\nrobert\nme");
strcpy(string2,"\nns");
if(ParseUser(string1,string2,user,password))
printf("User: %s\nPassword: %s\n",user,password);
else puts("ERROR....");
strcpy(string1,"login\nrwashington\nsecret");
if(ParseUser(string1,NULL,user,password))
printf("\nUser: %s\nPassword: %s\n",user,password);
else puts("ERROR....");
return 0;
}
int ParseUser(const string str1, const string str2, string user,
string passwd)
{
string tmp;
if(str1)
{
if(2 != sscanf(str1,"%*s\n%29s\n%29s",user,passwd))
return 0;
else
if(str2)
{
if(1 != sscanf(str2,"\n%29s",tmp))
return 0;
else
{
strncat(passwd,tmp,30-strlen(tmp));
passwd[29] = ''\0'';
}
}
}
return 1;
}
--
Al Bowers
Tampa, Fl USA
mailto: xa******@myrapidsys.com (remove the x to send email)
http://www.geocities.com/abowers822/
这篇关于等到\ n出现在字符串中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!