How to read string from keyboard using C?

You have no storage allocated for word – it’s just a dangling pointer. Change: char * word; to: char word[256]; Note that 256 is an arbitrary choice here – the size of this buffer needs to be greater than the largest possible string that you might encounter. Note also that fgets is a better (safer) … Read more

sscanf in Python

There is also the parse module. parse() is designed to be the opposite of format() (the newer string formatting function in Python 2.6 and higher). >>> from parse import parse >>> parse(‘{} fish’, ‘1’) >>> parse(‘{} fish’, ‘1 fish’) <Result (‘1’,) {}> >>> parse(‘{} fish’, ‘2 fish’) <Result (‘2’,) {}> >>> parse(‘{} fish’, ‘red fish’) … Read more

Disadvantages of scanf

Most of the answers so far seem to focus on the string buffer overflow issue. In reality, the format specifiers that can be used with scanf functions support explicit field width setting, which limit the maximum size of the input and prevent buffer overflow. This renders the popular accusations of string-buffer overflow dangers present in … Read more

How can I read an input string of unknown length?

Enter while securing an area dynamically E.G. #include <stdio.h> #include <stdlib.h> char *inputString(FILE* fp, size_t size){ //The size is extended by the input with the value of the provisional char *str; int ch; size_t len = 0; str = realloc(NULL, sizeof(*str)*size);//size is start size if(!str)return str; while(EOF!=(ch=fgetc(fp)) && ch != ‘\n’){ str[len++]=ch; if(len==size){ str = … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)