[Solved] Why basic C code throws Access violation

char arr[] = { ‘a’, ‘b’, ‘c’, ‘d’, ‘e’, ‘f’ }; printf(“%c”, arr[0]); %s says print all the characters until you find a null (treat the variable as a pointer). %c says print just one character (treat the variable as a character code) Using %s for a character doesn’t work because the character is going … Read more

[Solved] status of scanf(“%d”, &num) is 0 or 1

scanf is defined such that On success, the function returns the number of items successfully read. This count can match the expected number of readings or fewer, even zero, if a matching failure happens. In the case of an input failure before any data could be successfully read, EOF is returned. NAME scanf, fscanf, sscanf, … Read more

[Solved] C – why it’s return me NULL value every-time?

you call ft_strstr(“Bonjour”, “jour”); ft_strstr calls ft_memcmp(“onjour”, “jour”). ft_memcmp returns ‘o’ – ‘j’, which is not zero, so return (!ft_memcmp(++s1, s2, ft_strlen(s2)) ? s1 : NULL); returns NULL your problem is ft_strstr : I suppose you wanted to do it recursively ? If it is the case, you forgot the recursion Here’s an example of … Read more

[Solved] Re-casting c# variables with a different class

Couldn’t you refactor it so that you have a generic method that takes a WebResponse? public T Deserialize<T>(WebResponse response) where T: new() // ensure that any type of T used has a parameterless constructor { string r = “”; using (StreamReader sr = new StreamReader(res.GetResponseStream())) { r = sr.ReadToEnd(); } JavaScriptSerializer js = new JavaScriptSerializer(); … Read more

[Solved] sort vector of struct element

std::vector<student_t> st; for(unsigned i = 0; i < 10; ++i) st.push_back(student_t()); std::sort(st.begin(), st.end(), &compare); You could also use this vector constructor instead of lines 1-2: std::vector<student_t> st (10 /*, student_t() */); Edit: If you want to enter 10 students with the keyboard you can write a function that constructs a student: struct student_t &enter_student() { … Read more

[Solved] Why can’t we store addresses in normal int variables? and by assigning i dont want it to point anywhere.

why we need pointer variables… No, we don’t need pointer variables until… we need one. In other words, there are many cases (or algorithms) which don’t need pointers. But soon or later you realize that pointers are needed. Well, pointers contain values, which are different from integers, different from floating point numbers and so on. … Read more