توابع ورودی و خروجی، انواع داده ای و ماکروهای تعریف شده که در سرفایل <stdio.h> قرار دارند، تقریبا یک سوم کتابخانه استاندارد را تشکیل می دهند.

 

 

 

این مطلب در حال ویرایش است


typedef __FILE FILE;
typedef _fpos64_t fpos_t;
typedef _fpos_t fpos_t;
typedef _fpos64_t fpos64_t;

 

 

char * ctermid (char *);
char * cuserid (char *);
FILE * tmpfile (void);
char * tmpnam (char *);

char * tempnam (const char *, const char *) __malloc_like __result_use_check;

int fclose (FILE *);
int fflush (FILE *);
FILE * freopen (const char *__restrict, const char *__restrict, FILE *__restrict);
void setbuf (FILE *__restrict, char *__restrict);
int setvbuf (FILE *__restrict, char *__restrict, int, size_t);
int fprintf (FILE *__restrict, const char *__restrict, ...) _ATTRIBUTE ((__format__ (__printf__, 2, 3)));
int fscanf (FILE *__restrict, const char *__restrict, ...) _ATTRIBUTE ((__format__ (__scanf__, 2, 3)));
int printf (const char *__restrict, ...) _ATTRIBUTE ((__format__ (__printf__, 1, 2)));
int scanf (const char *__restrict, ...) _ATTRIBUTE ((__format__ (__scanf__, 1, 2)));


int sscanf (const char *__restrict, const char *__restrict, ...) _ATTRIBUTE ((__format__ (__scanf__, 2, 3)));

با تابع sscanf میتوان از متغییر رشته ای داده شده، اطلاعاتی که بصورت خاصی فرمت بندی شده اند را بیرون کشید و در متغیر دیگری ذخیره کرد. در بخش تعیین فرمت رشته از s% برای مقادیر رشته ای مثل نام، c% برای تک کاراکتر، d% برای مقادیر عددی و f% برای مقادیر اعشاری استفاده می شود.

نکته 1: اگر متغیر به صورت آرایه (Array) نباشد، باید علامت & را قبل از نام متغیر در تابع sscanf بنویسیم (در غیر این صورت، برنامه C با خطا روبرو می شود)

نکته 2: داشتن نشان * در بخش فرمت رشته یعنی اینکه آن رشته دیده شده ولی در پردازش قرار نمی گیرد و یا بعبارتی نادیده گرفته میشود.

نکته 3: برای اینکه بخواهیم دقیقا کاراکترهایی که مدنظر ماست، بررسی شود در بخش فرمت بندی از الگوی [ ]% استفاده میکنیم.

نکته 4: برای اینکه کاراکترهای خاصی در رشته بررسی نشود، از الگوی [^]% استفاده می شود. (فقط رشته ای مورد تایید قرار میگیرد که آن کاراکتر خاص در داخل آکولاد نباشد) 

#include<stdio.h>
#include<string.h>

int main(){
    char *str = "Tom Manager 28";
    char name[10], designation[10];
    int age, ret;

    ret = sscanf(str, "%s %s %d", name, designation, &age);

    printf("Name: %s\n", name);
    printf("Designation: %s\n", designation);
    printf("Age: %d\n", age);
}

OUTPUT:

Name: Tom
Designation: Manager
Age: 28


int vfprintf (FILE *__restrict, const char *__restrict, __VALIST) _ATTRIBUTE ((__format__ (__printf__, 2, 0)));
int vprintf (const char *, __VALIST) _ATTRIBUTE ((__format__ (__printf__, 1, 0)));
int vsprintf (char *__restrict, const char *__restrict, __VALIST) _ATTRIBUTE ((__format__ (__printf__, 2, 0)));
int fgetc (FILE *);
char * fgets (char *__restrict, int, FILE *__restrict);
int fputc (int, FILE *);
int fputs (const char *__restrict, FILE *__restrict);
int getc (FILE *);
int getchar (void);
char * gets (char *);
int putc (int, FILE *);
int putchar (int);
int puts (const char *);
int ungetc (int, FILE *);
size_t fread (void *__restrict, size_t _size, size_t _n, FILE *__restrict);
size_t fwrite (const void *__restrict , size_t _size, size_t _n, FILE *);

int fgetpos (FILE *, _fpos_t *);

int fgetpos (FILE *__restrict, fpos_t *__restrict);

int fseek (FILE *, long, int);

int fsetpos (FILE *, const _fpos_t *);

int fsetpos (FILE *, const fpos_t *);

long ftell ( FILE *);
void rewind (FILE *);
void clearerr (FILE *);
int feof (FILE *);
int ferror (FILE *);
void perror (const char *);

FILE * fopen (const char *__restrict _name, const char *__restrict _type);
int sprintf (char *__restrict, const char *__restrict, ...) _ATTRIBUTE ((__format__ (__printf__, 2, 3)));
int remove (const char *);
int rename (const char *, const char *);
#ifdef _COMPILING_NEWLIB
int _rename (const char *, const char *);

int fseeko (FILE *, _off_t, int);
_off_t ftello (FILE *);

int fseeko (FILE *, off_t, int);
off_t ftello (FILE *);

int fcloseall (void);

int snprintf (char *__restrict, size_t, const char *__restrict, ...) _ATTRIBUTE ((__format__ (__printf__, 3, 4)));
int vsnprintf (char *__restrict, size_t, const char *__restrict, __VALIST) _ATTRIBUTE ((__format__ (__printf__, 3, 0)));
int vfscanf (FILE *__restrict, const char *__restrict, __VALIST) _ATTRIBUTE ((__format__ (__scanf__, 2, 0)));
int vscanf (const char *, __VALIST) _ATTRIBUTE ((__format__ (__scanf__, 1, 0)));
int vsscanf (const char *__restrict, const char *__restrict, __VALIST) _ATTRIBUTE ((__format__ (__scanf__, 2, 0)));

int asprintf (char **__restrict, const char *__restrict, ...) _ATTRIBUTE ((__format__ (__printf__, 2, 3)));
int vasprintf (char **, const char *, __VALIST) _ATTRIBUTE ((__format__ (__printf__, 2, 0)));

int asiprintf (char **, const char *, ...) _ATTRIBUTE ((__format__ (__printf__, 2, 3)));
char * asniprintf (char *, size_t *, const char *, ...) _ATTRIBUTE ((__format__ (__printf__, 3, 4)));
char * asnprintf (char *__restrict, size_t *__restrict, const char *__restrict, ...) _ATTRIBUTE ((__format__ (__printf__, 3, 4)));

int diprintf (int, const char *, ...) _ATTRIBUTE ((__format__ (__printf__, 2, 3)));

int fiprintf (FILE *, const char *, ...) _ATTRIBUTE ((__format__ (__printf__, 2, 3)));
int fiscanf (FILE *, const char *, ...) _ATTRIBUTE ((__format__ (__scanf__, 2, 3)));
int iprintf (const char *, ...) _ATTRIBUTE ((__format__ (__printf__, 1, 2)));
int iscanf (const char *, ...) _ATTRIBUTE ((__format__ (__scanf__, 1, 2)));
int siprintf (char *, const char *, ...) _ATTRIBUTE ((__format__ (__printf__, 2, 3)));
int siscanf (const char *, const char *, ...) _ATTRIBUTE ((__format__ (__scanf__, 2, 3)));
int sniprintf (char *, size_t, const char *, ...) _ATTRIBUTE ((__format__ (__printf__, 3, 4)));
int vasiprintf (char **, const char *, __VALIST) _ATTRIBUTE ((__format__ (__printf__, 2, 0)));
char * vasniprintf (char *, size_t *, const char *, __VALIST) _ATTRIBUTE ((__format__ (__printf__, 3, 0)));
char * vasnprintf (char *, size_t *, const char *, __VALIST) _ATTRIBUTE ((__format__ (__printf__, 3, 0)));
int vdiprintf (int, const char *, __VALIST) _ATTRIBUTE ((__format__ (__printf__, 2, 0)));
int vfiprintf (FILE *, const char *, __VALIST) _ATTRIBUTE ((__format__ (__printf__, 2, 0)));
int vfiscanf (FILE *, const char *, __VALIST) _ATTRIBUTE ((__format__ (__scanf__, 2, 0)));
int viprintf (const char *, __VALIST) _ATTRIBUTE ((__format__ (__printf__, 1, 0)));
int viscanf (const char *, __VALIST) _ATTRIBUTE ((__format__ (__scanf__, 1, 0)));
int vsiprintf (char *, const char *, __VALIST) _ATTRIBUTE ((__format__ (__printf__, 2, 0)));
int vsiscanf (const char *, const char *, __VALIST) _ATTRIBUTE ((__format__ (__scanf__, 2, 0)));
int vsniprintf (char *, size_t, const char *, __VALIST) _ATTRIBUTE ((__format__ (__printf__, 3, 0)));

FILE * fdopen (int, const char *);

int fileno (FILE *);


int pclose (FILE *);
FILE * popen (const char *, const char *);


void setbuffer (FILE *, char *, int);
int setlinebuf (FILE *);


int getw (FILE *);
int putw (int, FILE *);


int getc_unlocked (FILE *);
int getchar_unlocked (void);
void flockfile (FILE *);
int ftrylockfile (FILE *);
void funlockfile (FILE *);
int putc_unlocked (int, FILE *);
int putchar_unlocked (int);

int dprintf (int, const char *__restrict, ...) _ATTRIBUTE ((__format__ (__printf__, 2, 3)));

FILE * fmemopen (void *__restrict, size_t, const char *__restrict);

FILE * open_memstream (char **, size_t *);
int vdprintf (int, const char *__restrict, __VALIST)

int renameat (int, const char *, int, const char *);

int renameat2 (int, const char *, int, const char *, unsigned int);

 

int _asiprintf_r (struct _reent *, char **, const char *, ...)_ATTRIBUTE ((__format__ (__printf__, 3, 4)));
char * _asniprintf_r (struct _reent *, char *, size_t *, const char *, ...)_ATTRIBUTE ((__format__ (__printf__, 4, 5)));
char * _asnprintf_r (struct _reent *, char *__restrict, size_t *__restrict, const char *__restrict, ...)_ATTRIBUTE ((__format__ (__printf__, 4, 5)));

int _asprintf_r (struct _reent *, char **__restrict, const char *__restrict, ...)_ATTRIBUTE ((__format__ (__printf__, 3, 4)));
int _diprintf_r (struct _reent *, int, const char *, ...)_ATTRIBUTE ((__format__ (__printf__, 3, 4)));
int _dprintf_r (struct _reent *, int, const char *__restrict, ...)_ATTRIBUTE ((__format__ (__printf__, 3, 4)));
int _fclose_r (struct _reent *, FILE *);
int _fcloseall_r (struct _reent *);
FILE * _fdopen_r (struct _reent *, int, const char *);
int _fflush_r (struct _reent *, FILE *);
int _fgetc_r (struct _reent *, FILE *);
int _fgetc_unlocked_r (struct _reent *, FILE *);
char * _fgets_r (struct _reent *, char *__restrict, int, FILE *__restrict);
char * _fgets_unlocked_r (struct _reent *, char *__restrict, int, FILE *__restrict);

int _fgetpos_r (struct _reent *, FILE *__restrict, _fpos_t *__restrict);
int _fsetpos_r (struct _reent *, FILE *, const _fpos_t *);

int _fgetpos_r (struct _reent *, FILE *, fpos_t *);
int _fsetpos_r (struct _reent *, FILE *, const fpos_t *);

int _fiprintf_r (struct _reent *, FILE *, const char *, ...)_ATTRIBUTE ((__format__ (__printf__, 3, 4)));
int _fiscanf_r (struct _reent *, FILE *, const char *, ...)_ATTRIBUTE ((__format__ (__scanf__, 3, 4)));
FILE * _fmemopen_r (struct _reent *, void *__restrict, size_t, const char *__restrict);
FILE * _fopen_r (struct _reent *, const char *__restrict, const char *__restrict);
FILE * _freopen_r (struct _reent *, const char *__restrict, const char *__restrict, FILE *__restrict);
int _fprintf_r (struct _reent *, FILE *__restrict, const char *__restrict, ...)_ATTRIBUTE ((__format__ (__printf__, 3, 4)));
int _fpurge_r (struct _reent *, FILE *);
int _fputc_r (struct _reent *, int, FILE *);
int _fputc_unlocked_r (struct _reent *, int, FILE *);
int _fputs_r (struct _reent *, const char *__restrict, FILE *__restrict);
int _fputs_unlocked_r (struct _reent *, const char *__restrict, FILE *__restrict);
size_t _fread_r (struct _reent *, void *__restrict, size_t _size, size_t _n, FILE *__restrict);
size_t _fread_unlocked_r (struct _reent *, void *__restrict, size_t _size, size_t _n, FILE *__restrict);
int _fscanf_r (struct _reent *, FILE *__restrict, const char *__restrict, ...)_ATTRIBUTE ((__format__ (__scanf__, 3, 4)));
int _fseek_r (struct _reent *, FILE *, long, int);
int _fseeko_r (struct _reent *, FILE *, _off_t, int);
long _ftell_r (struct _reent *, FILE *);
_off_t _ftello_r (struct _reent *, FILE *);
void _rewind_r (struct _reent *, FILE *);
size_t _fwrite_r (struct _reent *, const void *__restrict, size_t _size, size_t _n, FILE *__restrict);
size_t _fwrite_unlocked_r (struct _reent *, const void *__restrict, size_t _size, size_t _n, FILE *__restrict);
int _getc_r (struct _reent *, FILE *);
int _getc_unlocked_r (struct _reent *, FILE *);
int _getchar_r (struct _reent *);
int _getchar_unlocked_r (struct _reent *);
char * _gets_r (struct _reent *, char *);
int _iprintf_r (struct _reent *, const char *, ...)_ATTRIBUTE ((__format__ (__printf__, 2, 3)));
int _iscanf_r (struct _reent *, const char *, ...)_ATTRIBUTE ((__format__ (__scanf__, 2, 3)));
FILE * _open_memstream_r (struct _reent *, char **, size_t *);
void _perror_r (struct _reent *, const char *);
int _printf_r (struct _reent *, const char *__restrict, ...)_ATTRIBUTE ((__format__ (__printf__, 2, 3)));
int _putc_r (struct _reent *, int, FILE *);
int _putc_unlocked_r (struct _reent *, int, FILE *);
int _putchar_unlocked_r (struct _reent *, int);
int _putchar_r (struct _reent *, int);
int _puts_r (struct _reent *, const char *);
int _remove_r (struct _reent *, const char *);
int _rename_r (struct _reent *,const char *_old, const char *_new);
int _scanf_r (struct _reent *, const char *__restrict, ...)_ATTRIBUTE ((__format__ (__scanf__, 2, 3)));
int _siprintf_r (struct _reent *, char *, const char *, ...)_ATTRIBUTE ((__format__ (__printf__, 3, 4)));
int _siscanf_r (struct _reent *, const char *, const char *, ...)_ATTRIBUTE ((__format__ (__scanf__, 3, 4)));
int _sniprintf_r (struct _reent *, char *, size_t, const char *, ...)_ATTRIBUTE ((__format__ (__printf__, 4, 5)));
int _snprintf_r (struct _reent *, char *__restrict, size_t, const char *__restrict, ...)_ATTRIBUTE ((__format__ (__printf__, 4, 5)));
int _sprintf_r (struct _reent *, char *__restrict, const char *__restrict, ...)_ATTRIBUTE ((__format__ (__printf__, 3, 4)));
int _sscanf_r (struct _reent *, const char *__restrict, const char *__restrict, ...)_ATTRIBUTE ((__format__ (__scanf__, 3, 4)));
char * _tempnam_r (struct _reent *, const char *, const char *);
FILE * _tmpfile_r (struct _reent *);
char * _tmpnam_r (struct _reent *, char *);
int _ungetc_r (struct _reent *, int, FILE *);
int _vasiprintf_r (struct _reent *, char **, const char *, __VALIST)_ATTRIBUTE ((__format__ (__printf__, 3, 0)));
char * _vasniprintf_r (struct _reent*, char *, size_t *, const char *, __VALIST)_ATTRIBUTE ((__format__ (__printf__, 4, 0)));
char * _vasnprintf_r (struct _reent*, char *, size_t *, const char *, __VALIST)_ATTRIBUTE ((__format__ (__printf__, 4, 0)));
int _vasprintf_r (struct _reent *, char **, const char *, __VALIST)_ATTRIBUTE ((__format__ (__printf__, 3, 0)));
int _vdiprintf_r (struct _reent *, int, const char *, __VALIST)_ATTRIBUTE ((__format__ (__printf__, 3, 0)));
int _vdprintf_r (struct _reent *, int, const char *__restrict, __VALIST)_ATTRIBUTE ((__format__ (__printf__, 3, 0)));
int _vfiprintf_r (struct _reent *, FILE *, const char *, __VALIST)_ATTRIBUTE ((__format__ (__printf__, 3, 0)));
int _vfiscanf_r (struct _reent *, FILE *, const char *, __VALIST)_ATTRIBUTE ((__format__ (__scanf__, 3, 0)));
int _vfprintf_r (struct _reent *, FILE *__restrict, const char *__restrict, __VALIST)_ATTRIBUTE ((__format__ (__printf__, 3, 0)));
int _vfscanf_r (struct _reent *, FILE *__restrict, const char *__restrict, __VALIST)_ATTRIBUTE ((__format__ (__scanf__, 3, 0)));
int _viprintf_r (struct _reent *, const char *, __VALIST)_ATTRIBUTE ((__format__ (__printf__, 2, 0)));
int _viscanf_r (struct _reent *, const char *, __VALIST)_ATTRIBUTE ((__format__ (__scanf__, 2, 0)));
int _vprintf_r (struct _reent *, const char *__restrict, __VALIST)_ATTRIBUTE ((__format__ (__printf__, 2, 0)));
int _vscanf_r (struct _reent *, const char *__restrict, __VALIST)_ATTRIBUTE ((__format__ (__scanf__, 2, 0)));
int _vsiprintf_r (struct _reent *, char *, const char *, __VALIST)_ATTRIBUTE ((__format__ (__printf__, 3, 0)));
int _vsiscanf_r (struct _reent *, const char *, const char *, __VALIST)_ATTRIBUTE ((__format__ (__scanf__, 3, 0)));
int _vsniprintf_r (struct _reent *, char *, size_t, const char *, __VALIST)_ATTRIBUTE ((__format__ (__printf__, 4, 0)));
int _vsnprintf_r (struct _reent *, char *__restrict, size_t, const char *__restrict, __VALIST)_ATTRIBUTE ((__format__ (__printf__, 4, 0)));
int _vsprintf_r (struct _reent *, char *__restrict, const char *__restrict, __VALIST)_ATTRIBUTE ((__format__ (__printf__, 3, 0)));
int _vsscanf_r (struct _reent *, const char *__restrict, const char *__restrict, __VALIST)_ATTRIBUTE ((__format__ (__scanf__, 3, 0)));

int fpurge (FILE *);
ssize_t __getdelim (char **, size_t *, int, FILE *);
ssize_t __getline (char **, size_t *, FILE *);


void clearerr_unlocked (FILE *);
int feof_unlocked (FILE *);
int ferror_unlocked (FILE *);
int fileno_unlocked (FILE *);
int fflush_unlocked (FILE *);
int fgetc_unlocked (FILE *);
int fputc_unlocked (int, FILE *);
size_t fread_unlocked (void *__restrict, size_t _size, size_t _n, FILE *__restrict);
size_t fwrite_unlocked (const void *__restrict , size_t _size, size_t _n, FILE *);


char * fgets_unlocked (char *__restrict, int, FILE *__restrict);
int fputs_unlocked (const char *__restrict, FILE *__restrict);


FILE * fdopen64 (int, const char *);
FILE * fopen64 (const char *, const char *);
FILE * freopen64 (const char *, const char *, FILE *);
_off64_t ftello64 (FILE *);
_off64_t fseeko64 (FILE *, _off64_t, int);
int fgetpos64 (FILE *, _fpos64_t *);
int fsetpos64 (FILE *, const _fpos64_t *);
FILE * tmpfile64 (void);

FILE * _fdopen64_r (struct _reent *, int, const char *);
FILE * _fopen64_r (struct _reent *,const char *, const char *);
FILE * _freopen64_r (struct _reent *, const char *, const char *, FILE *);
_off64_t _ftello64_r (struct _reent *, FILE *);
_off64_t _fseeko64_r (struct _reent *, FILE *, _off64_t, int);
int _fgetpos64_r (struct _reent *, FILE *, _fpos64_t *);
int _fsetpos64_r (struct _reent *, FILE *, const _fpos64_t *);
FILE * _tmpfile64_r (struct _reent *);

int __srget_r (struct _reent *, FILE *);
int __swbuf_r (struct _reent *, int, FILE *);

 

FILE *funopen (const void *__cookie,int (*__readfn)(void *__c, char *__buf,_READ_WRITE_BUFSIZE_TYPE __n),int (*__writefn)(void *__c, const char *__buf,_READ_WRITE_BUFSIZE_TYPE __n),_fpos64_t (*__seekfn)(void *__c, _fpos64_t __off, int __whence),int (*__closefn)(void *__c));
FILE *_funopen_r (struct _reent *, const void *__cookie,int (*__readfn)(void *__c, char *__buf,_READ_WRITE_BUFSIZE_TYPE __n),int (*__writefn)(void *__c, const char *__buf,_READ_WRITE_BUFSIZE_TYPE __n),_fpos64_t (*__seekfn)(void *__c, _fpos64_t __off, int __whence),int (*__closefn)(void *__c));

FILE *funopen (const void *__cookie,int (*__readfn)(void *__cookie, char *__buf,_READ_WRITE_BUFSIZE_TYPE __n),int (*__writefn)(void *__cookie, const char *__buf,_READ_WRITE_BUFSIZE_TYPE __n),fpos_t (*__seekfn)(void *__cookie, fpos_t __off, int __whence),int (*__closefn)(void *__cookie));
FILE *_funopen_r (struct _reent *, const void *__cookie,int (*__readfn)(void *__cookie, char *__buf,_READ_WRITE_BUFSIZE_TYPE __n),int (*__writefn)(void *__cookie, const char *__buf,_READ_WRITE_BUFSIZE_TYPE __n),fpos_t (*__seekfn)(void *__cookie, fpos_t __off, int __whence),int (*__closefn)(void *__cookie));

typedef ssize_t cookie_read_function_t(void *__cookie, char *__buf, size_t __n);
typedef ssize_t cookie_write_function_t(void *__cookie, const char *__buf,size_t __n);

typedef int cookie_seek_function_t(void *__cookie, _off64_t *__off,int __whence);

typedef int cookie_seek_function_t(void *__cookie, off_t *__off, int __whence);

typedef int cookie_close_function_t(void *__cookie);
typedef struct
{
cookie_read_function_t *read;
cookie_write_function_t *write;
cookie_seek_function_t *seek;
cookie_close_function_t *close;
} cookie_io_functions_t;
FILE *fopencookie (void *__cookie,
const char *__mode, cookie_io_functions_t __functions);
FILE *_fopencookie_r (struct _reent *, void *__cookie,
const char *__mode, cookie_io_functions_t __functions);

 

_ELIDABLE_INLINE int __sgetc_r(struct _reent *__ptr, FILE *__p);

_ELIDABLE_INLINE int __sgetc_r(struct _reent *__ptr, FILE *__p)
{
int __c = __sgetc_raw_r(__ptr, __p);
if ((__p->_flags & __SCLE) && (__c == '\r'))
{
int __c2 = __sgetc_raw_r(__ptr, __p);
if (__c2 == '\n')
__c = __c2;
else
ungetc(__c2, __p);
}
return __c;
}

نوشتن دیدگاه