PDA

View Full Version : سوال: كنار امدن با عدم string در زبان سي



amirrenjer
سه شنبه 17 تیر 1393, 23:27 عصر
سلام دوستان خسته نباشيد
من ميخواستم ي متن ( شامل كاركتر و عدد و...) دريافت كنم و روي اون ي سري فيلتر كنم و مثلا اعداد رو دربيارم اما زبان سي كه string نداره بايد جكار كرد؟؟؟! ممنونم:اشتباه:

emadrezvani
سه شنبه 17 تیر 1393, 23:31 عصر
بسته به نوع ورودی باید تصمیم گرفت.
ساده ترین حالت هم getch به همراه sprintf و ... هست.

مسعود اقدسی فام
سه شنبه 17 تیر 1393, 23:33 عصر
زبان C آرایه‌ی از کاراکترها رو به عنوان رشته داره:


char test[] = "Hello";


و ++C نوع string رو هم اضافه کرده:



string test = "Hello";


توابعی برای کار با این رشته‌ها هم وجود دارن که داخل فایل‌های string,h و string تعریف شدن.

amirrenjer
چهارشنبه 18 تیر 1393, 10:23 صبح
خیلی ممنون :-)

فقط من دنبال یه سری توابع زبون سی میگردم ممنون میشم اگه کتاب مناسبی هست معرفی کنین ترجیحا پی دی اف.

مثلا سی شارپ تابع contain داره که من تو سی خیلی بش نیاز دارم :اشتباه:

محمد فدوی
چهارشنبه 18 تیر 1393, 10:44 صبح
این دو تا رو ببین:
لینک اول (http://en.wikipedia.org/wiki/C_string_handling) - لینک دوم (http://faculty.edcc.edu/paul.bladek/c_string_functions.htm)

amirrenjer
پنج شنبه 19 تیر 1393, 12:49 عصر
ممنون ولی این تابع ها برای سی++ هستن گمونم...من برای سی و پروگرام کردن میکرو میخوام ک فک نکنم بشه تو کدویژن استفاده کرد :افسرده:

emadrezvani
پنج شنبه 19 تیر 1393, 13:02 عصر
کدویژن string.h مگه نداره ؟!



CodeVisionAVR
© 1998-2007 HP InfoTech S.R.L.
Page 123
4.5 String Functions
The prototypes for these func
tions are placed in the file
string.h
, located in the ..\INC subdirectory.
This file must be
#include
-ed before using the functions.

The string manipulation functions were extended to
handle strings located both in SRAM and FLASH
memories.

char *strcat(char *str1, char *str2)


concatenate the string str2
to the end of the string str1.

char *strcatf(char *str1, char flash *str2)


concatenate the string str2, located in
FLASH, to the end of the string str1.

char *strncat(char *str1, char *str2, unsigned char n)


concatenate maximum n characters of the st
ring str2 to the end of the string str1.
Returns a pointer to the string str1.

char *strncatf(char *str1, char flash *str2, unsigned char n)


concatenate maximum n characters of the string
str2, located in FLASH, to the end of the string
str1.
Returns a pointer to the string str1.

char *strchr(char *str, char c)


returns a pointer to the first occurrence of the
character c in the string str, else a NULL pointer.

char *strrchr(char *str, char c)


returns a pointer to the last occurrence of the
character c in the string str, else a NULL pointer.

signed char strpos(char *str, char c)


returns the index to first occurrence of
the character c in the string str, else -1.

signed char strrpos(char *str, char c)


returns the index to the last occurrence of
the character c in the string str, else -1.

signed char strcmp(char *str1, char *str2)


compares the string str1 with the string str2.
Returns <0, 0, >0 according to st
r1<str2, str1=str2, str1>str2.

signed char strcmpf(char *str1, char flash *str2)


compares the string str1, located in SRAM
, with the string str2, located in FLASH.
Returns <0, 0, >0 according to st
r1<str2, str1=str2, str1>str2.

signed char strncmp(char *str1, char *str2, unsigned char n)

compares at most n characters of
the string str1 with the string str2.
Returns <0, 0, >0 according to st
r1<str2, str1=str2, str1>str2.


CodeVisionAVR
© 1998-2007 HP InfoTech S.R.L.
Page 124

signed char strncmpf(char *str1, char flash *str2, unsigned char n)


compares at most n characters of
the string str1, located in SRAM, with the string str2, located in
FLASH.
Returns <0, 0, >0 according to st
r1<str2, str1=str2, str1>str2.

char *strcpy(char *dest, char *src)

copies the string src to the string dest.

char *strcpyf(char *dest, char flash *src)


copies the string src, located in FL
ASH, to the string dest, located in SRAM.
Returns a pointer to the string dest.

char *strncpy(char *dest, char *src, unsigned char n)

copies at most n characters from the
string src to the string dest (null padding).
Returns a pointer to the string dest.

char *strncpyf(char *dest, char flash *src, unsigned char n)

copies at most n characters from the string src,
located in FLASH, to the string dest, located in
SRAM (null padding).
Returns a pointer to the string dest.

unsigned char strspn(char *str, char *set)


returns the index of the first character, from the
string str, that doesn't
match a character from the
string set.
If all characters from set are in str returns the length of str.

unsigned char strspnf(char *str, char flash *set)


returns the index of the first character, from the
string str, located in SRAM, that doesn't match a
character from the string set, located in FLASH.
If all characters from set are in str returns the length of str.

unsigned char strcspn(char *str, char *set)


searches the string str for the first occu
rrence of a character from the string set.
If there is a match returns, the
index of the character in str.
If there are no matching characters, returns the length of str.

unsigned char strcspnf(char *str, char flash *set)


searches the string str for the first occurrence of
a character from the string set, located in FLASH.
If there is a match, returns the
index of the character in str.
If there are no matching characters, returns the length of str.

char *strpbrk(char *str, char *set)


searches the string str for the first oc
currence of a char from the string set.
If there is a match, returns a pointer to the character in str.
If there are no matching characters, returns a NULL pointer.



CodeVisionAVR
© 1998-2007 HP InfoTech S.R.L.
Page 125

char *strpbrkf(char *str, char flash *set)


searches the string str, located in SRAM, for the
first occurrence of a char from the string set,
located in FLASH.
If there is a match, returns a pointer to the character in str.
If there are no matching characters, returns a NULL pointer.

char *strrpbrk(char *str, char *set)

searches the string str for the last occu
rrence of a character from the string set.
If there is a match, returns a pointer to the character in str.
If there are no matching characters, returns a NULL pointer.

char *strrpbrkf(char *str, char flash *set)


searches the string str, located in SRAM, for the la
st occurrence of a character from the string set,
located in FLASH.
If there is a match, returns a pointer to the character in str.
If there are no matching characters, returns a NULL pointer.

char *strstr(char *str1, char *str2)

searches the string str1 for the fi
rst occurrence of the string str2.
If there is a match, returns a pointer to the character in str1 where str2 begins.
If there is no match, returns a NULL pointer.

char *strstrf(char *str1, char flash *str2)

searches the string str1, located in SRAM, for t
he first occurrence of the string str2, located in
FLASH.
If there is a match, returns a pointer to the character in str1 where str2 begins.
If there is no match, returns a NULL pointer.

char *strtok(char *str1, char flash *str2)

scans the string str1, located in SRAM, for the firs
t token not contained in the string str2, located in
FLASH.
The function considers the string str1 as consisting of a sequence of text tokens, separated by spans
of one or more characters from the string str2.
The first call to strtok, with the pointer to str1 bei
ng different from NULL, returns a pointer to the first
character of the first token in str1. Also a NULL ch
aracter will be written in str1, immediately after the
returned token.
Subsequent calls to strtok, with
NULL as the first parameter, will work
through the string str1 until no
more tokens remain. When there are no more
tokens, strtok will
return a NULL pointer.

unsigned char strlen(char *str)


for the TINY memory model.

returns the length of the string str (in the
range 0..255), excluding the null terminator.

unsigned int strlen(char *str)


for the SMALL memory model.

returns the length of the string str (in the r
ange 0..65535 ), excluding the null terminator.

unsigned int strlenf(char flash *str)


returns the length of the string str located in FLASH, excluding the null terminator.


CodeVisionAVR
© 1998-2007 HP InfoTech S.R.L.
Page 126

void *memcpy(void *dest,void *src, unsigned char n)


for the TINY memory model.


void *memcpy(void *dest,void *src, unsigned int n)



for the SMALL memory model.


Copies n bytes from src to dest. dest
must not overlap src, else use
memmove
.
Returns a pointer to dest.

void *memcpyf(void *dest,void flash *src, unsigned char n)


for the TINY memory model.


void *memcpyf(void *dest,void flash *src, unsigned int n)


for the SMALL memory model.

Copies n bytes from src, located in FL
ASH, to dest. Returns a pointer to dest.

void *memccpy(void *dest,void *src, char c, unsigned char n)



for the TINY memory model.

void *memccpy(void *dest,void *src, char c, unsigned int n)


for the SMALL memory model.

Copies at most n bytes from src to
dest, until the character c is copied.
dest must not overlap src.
Returns a NULL pointer if the last copied character was c or a pointer to dest+n+1.

void *memmove(void *dest,void *src, unsigned char n)


for the TINY memory model.


void *memmove(void *dest,void *src, unsigned int n)


for the SMALL memory model.

Copies n bytes from src to dest. dest may overlap src.
Returns a pointer to dest.

void *memchr(void *buf, unsigned char c, unsigned char n)

for the TINY memory model.

void *memchr(void *buf, unsigned char c, unsigned int n)


for the SMALL memory model.


Scans n bytes from buf for byte c.
Returns a pointer to c if found or a NULL pointer if not found.

signed char memcmp(void *buf1,void *buf2, unsigned char n)


for the TINY memory model.


CodeVisionAVR
© 1998-2007 HP InfoTech S.R.L.
Page 127

signed char memcmp(void *buf1,void *buf2, unsigned int n)

for the SMALL memory model.

Compares at most n bytes of buf1 with buf2.
Returns <0, 0, >0 according to buf1<buf2, buf1=buf2, buf1>buf2.

signed char memcmpf(void *buf1,void flash *buf2, unsigned char n)

for the TINY memory model.

signed char memcmpf(void *buf1,void flash *buf2, unsigned int n)


for the SMALL memory model.


Compares at most n bytes of buf1, locat
ed in SRAM, with buf2, located in FLASH.
Returns <0, 0, >0 according to buf1<buf2, buf1=buf2, buf1>buf2.

void *memset(void *buf, unsigned char c, unsigned char n)



for the TINY memory model.

void *memset(void *buf, unsigned char c, unsigned int n)



for the SMALL memory model.

Sets n bytes from buf with byte c. Returns a pointer to buf.

amirrenjer
پنج شنبه 19 تیر 1393, 14:00 عصر
اقا ممنون مشکلم حل شد :قلب:.

معلومه شما با میکرو هم کار کردین...میتونم ی سوال بپرسم؟

ا من ميخواستم يه برنامه بنويسم که که يه سري شماره توي ميکرو سيو بشه،بعد ميکرو اين شماره هارو در بياره و حالا بررسي کنه ،تغييرشون بده و يه سري شماره خودش بسازه و ... و در اخرم سيو کنه!بايد از چ حافظه اي استفاده کنم؟(اي 2 پي رام؟)

و اينکه اين ليست شماره رو چجوري بهش بدم؟؟!! http://www.eca.ir/forum2/Smileys/phpbb/icon_rolleyes.gif

emadrezvani
پنج شنبه 19 تیر 1393, 15:28 عصر
بله. کار کردم.
بسته به نوع و اندازه داده های شما باید حافظه رو مشخص کرد. اگه تعداد داده ها کم هست که حافظه خود میکرو جواب میده. اما اگه نیست و خیلی بیشتره امکان داره تا حد حافظه sd هم نیاز داشته باشید. ( eeprom میکرو ها اصولا برای کارهای کوچیک خوب هست اما اگه کم بیارید میتونید از IC های اون استفاده کنید)

amirrenjer
پنج شنبه 19 تیر 1393, 15:38 عصر
روی 200 شماره 14و15 رقمی!

حالا چجوری لیست شماره رو بدم و سیوشون کنم که با قطع برق از بین نره؟! آرایه؟(میکرو بعدا باید ی شماره رو پاک کنه و اضافه کنه و ...)

ممنون:خجالت:

emadrezvani
پنج شنبه 19 تیر 1393, 15:46 عصر
ذخیره و بازیابی توی eeprom به معنی آرایه و یا .. نیست! شما یه حافظه از 0 تا ... دارید و باید از اون بخونید. فکر کنم لینک زیر کار شمارو راه میندازه:
http://powercontrol.mihanblog.com/extrapage/2126

amirrenjer
پنج شنبه 19 تیر 1393, 16:01 عصر
اقا لطف کردی :-) فقط امیدوارم کارم با همین حافظه راه بیفته و نیاز ب حافظه جانبی نداشته باشم

emadrezvani
پنج شنبه 19 تیر 1393, 16:05 عصر
انشاا.. که راه بیافته . اما توصیه میکنم از علم فرار نکنید. حتما در اوقات بیکاری روی حافظه های جانبی مثل SD کار کنید.