why am i getting user bin error when following steps from cs50 video - cs50

My code attached
week 1 cs50 - Minute 38
I'm really not sure why I'm getting this error I'm really struggling to find the answer any help is appreciated.
i have copied everything David Malan did in the video. I'm not sure what I'm doing wrong.
the error is also attached below.
CS50 video

A couple of things. Instead of declaring your variable as a "string" you probably would want to declare it as a "char *" (e.g. char * answer) or char with a specific size allocation (e.g. char answer[32]).
You are indeed placing the input value into a string called "answer", but in your "printf" statement, the literal "answer" is just a word that is a part of a constant string you are printing out to your terminal. What you would want to do is something like this:
char * answer = get_string("What is your name");
printf("Hello %s\n", answer);
Hope that helps.
Regards.

Related

How to retrieve text by xpath

Hey everyone
I am 15 years old and I'm currently making a python/selenium script that automatically loges in on my school page and goes in to see what homework i have tomorrow.
The way I want it to check if we have received homework is if the text box which is: "LB MAT 86" is something else (because that means we have received homework)
Let me now tell you about my problem:
Picture: https://i.stack.imgur.com/WLjuR.png
But first, let me tell u how my "homework page" is designed and works.
On the picture you see that I have inspected the text: "LB MAT 86".
LB is the abbreviation of my teachers name.
MAT stands for "matematik" with just means math in english.
86 is the class number our class have.
When we get homework our teacher deletes the text "LB MAT 86" and instead writes the homework we get.
My question for you is how can I find the text. The only way I can see how you can find the text is by its location.
The xpath of the text field: //*[#id="sk-diary-notes-container"]/div/div[1]/div/table/tbody/tr[3]/td[3]/text()[1]
The full xpath of the text field: /html/body/div[1]/div[2]/div[3]/div[2]/div/div/div[1]/div/table/tbody/tr[3]/td[3]/text()[1]
OuterHTML:   LB MAT 86
Thanks
driver.find_element_by_xpath("//table[contains(#align,'center')//td[contains(.,'LB MAT 86')]")
Would get the element with text LB MAT 86.
You can add some code to find the current index to check for your code. /tr[i]/td[i]
Try using this xpath
locator = driver.find_element_by_xpath("//table[contains(#align,'center')/tbody/tr[3]/td[3]")
You should get everything including nbsp (non-braking space).
Then split the result and get everything after nbsp;
You did not include html code, only screenshot. Next time include it (or include it now).
After you test the correct locator, try to use split(). It will get the last element from your text divided by space. I am not 100% sure it will work, experiment by yourself.
mystring = locator.text
desired_text = result = mystring.split(' ')[-1]

Need XORd briefly explained for Cryptopals Crypto Challenge 3 set 1

i just have a quick question on this bit of code i have here on the Cryptopals Challenges, using Python3, For XORing a string with one single character.The program takes in a hex string string, decodes it, XORs it with a single character, does this for every possible character, then finds the "most english" line of XORd data. heres my code snippet (which i admittdly used from a solutions page ) :
def singlechar_xor(input_bytes, key_value):
"""XORs every byte of the input with the given key_value and returns the result."""
output = b''
for char in input_bytes:
output += bytes([char ^ key_value])
return output
i know what is happening and i understand what is supposed to happen, im just not sure how bytes behave and what types are and arent supposed to be XORd. Why do i need the brackets around char^key_value? If i remove the brackets my output becomes a bunch of 0's. What is the result of the XOR or the character and the key_value? If someone could kindly explain so i could have a better understanding going forward in these challenges id GREATLY appreciate it <3

Write text to file function python

so I would like to ask you for help.
I was scooping and sweeping the internet so long for that and I did not find how to do it. What I just produced is totally wrong and my professor did bad time with formulating the task. it is entry level task on university I have already finished the hardest ones, but this one I just dont get what he wants
Translation is made by me so it might be little bit off, but bear with me, please.
"Create file "linewriter.py". This file will have function writeTextToFile, that will accept one parameter and on end is also one parameter. Function will take the parameter on input and chain it with variable STATIC_TEXT (stated bellow). Queue of chaining will be as follows: 1st static text and then argument of function. This way chained input will write to file of any given name and a the name of this file will be returned as input parameter of function.
STATIC_TEXT: “This is my static text which must be added to file. It is very long text and I do not know what they want to do with this terrible text. ”
...
What? I really don't get what he want's from me. Can you help? Thank you all :)
STATICKY_TEXT = "This is my static text which must be added to file. It is very long text and I do not know what they want to do with this terrible text.\nNew Line! "
saveFile = open ("exampleFile.txt","w")
saveFile.write(STATICKY_TEXT)
saveFile.close()
solved it :) but I COULD not figure it out for days haha ... silly me

How to use strstrip for parsing a string in two parts

I would like to know hot to parse a string like this "hello world" into "helloworld" using the strstrip kernel function. I am developing a Linux Kernel char device and this functions causes me a Kernel Panic (or Kernel Opss).
The way I'm using this function is the following:
char result[100];
strcpy(result, "hello world");
strstrip(result);
strstrip(&result); //Also tried this
strstrip("100+200"); //Also tried this
The Kernel error is caused as soon as the strstrip line gets executed. What is the proper way to call this function?
Actually strstrip helps to remove the white spaces at the front. It does not remove all the white spaces with in the string.
Please look at the below example.
char result[100];
strcpy(result, " hello world from stack exchange");
printk("\n before: %s",result);
strcpy(result, strstrip((char*)result));
printk("\n after: %s",result);
Hope it helps.
srtstrip() is a wrapper function for strim() (http://lxr.linux.no/linux+v3.11.2/lib/string.c#L361) in modern kernels. As it will attempt to modify the string itself, you cannot call it with a static string as you have in the third attempt.
The second attempt you have is passing a pointer to an array variable which is also a pointer. So you are passing a char** which if you look at the link above you can see is not correct.
The first attempt should not cause a kernel error, but you do not appear to be receiving the return value in a a local variable. What kind of error are you receiving? I will update this answer if you can provide that information.
In the end though as Balamurugan A points out, this function does not do what you seem to think it does. strsep() (http://lxr.linux.no/linux+v3.11.2/lib/string.c#L485) may help you out here but it will only be a stepping stone to removing all spaces. You will actually have to copy the string into a new buffer word by word as there is not way to simply "shift memory contents", as it were.

order of execution in do/while loop

I took the following example literally from Walter Savitch Absolute C++ book. It works (as one would expect from a scholar such as Walter Savitch). However, I am puzzled why as I will explain after the code citation:
cout << "Enter a line of input and I will echo it:\n";
char symbol;
do
{
cin.get(symbol);
cout << symbol;
} while (symbol != '\n');
cout << "That's all for this demonstration.\n";
Possible output will look as follows:
Enter a line of input and I will echo it:
Do Be Do 1 2 34
Do Be Do 1 2 34
That's all for this demonstration.
My problem is the following. In going through the loop just once, cin.get(symbol) will find one character at a time, and cout will then output this one character consequently. Then, if my input wasn't a '\n' character, it will go into the loop for the second time, and so on, until finally the input equals '\n'.
However, in executing the code, all the input seems to be read at once, and then copied back at once. How can this happen if every input character needs to be checked to be equal to '\n'?
Final point, probably stating the obvious: this question does not pertain to code that is some way not syntactical. I am just puzzled about what happens during compilation and/or execution of the simple code I present above.
Hopefully someone can help me out!
Thanks.
Your observation is correct. It seems like all the input is read at once and then, printed out at once. The reason is that when the output is printed, it goes into a buffer which actually gets printed only when the buffer reaches a certain size, or whenever the code is all done. In the latter case, the output stream is closed and gets flushed. Practically speaking, this code is being printed but into a buffer.
Well it looks like it's gettings handled at once, because it is. The loop is going on exactly as you've written - keeps on writing the char until it meets the end of line mark. There isn't really much logic behind it :)

Resources