How to make new line with vim language? - concatenation

I want to know how to implement a new line (\n) in vim language; without using regex.
When i use this instruction, the result is :
^#
But no new line...
Thanks

I am not sure, what exactly you want, but to put a new line in the buffer, simply enter :put =
Alternatively, you can use :call append(1, 'foobar')

Related

How to skip scanning a line when piping in input?

I am trying to pipe in input through stdin in the C programming language. I have a text file that I would like to read, however, the first line is just the header, so I need to somehow skip it and read the rest.
Example:
Name Grade Points Average
Lea A 4.0 3.3
...
I would like to place each line in a node as part of a linked list and so far all I have are the structures. I am unsure of how I am supposed to read the file.
For reference, what type in the command line will be the following:
./codename < input.txt
Thank you!
Use tail with -n:
tail -n+2 input.txt | codename
Alternatively, if you must read the file directly via the < operator, the easiest way is to call getline and throw out the output. You could also do something similar with fgets. You will have to modify the program directly to do that however.

how to get the file extension in pike

I'm working on a program in pike and looking for a method like the endswith() in python- a method that gives me the extension of a given file.
Can someone help me with that?
thank you
Python's endswith() is something like Pike's has_suffix(string s, string suffix):
has_suffix("index.html", ".html");
Reference:
http://pike.lysator.liu.se/generated/manual/modref/ex/predef_3A_3A/has_suffix.html
extract the end of the string, and compare it with the desired extension:
"hello.html"[<4..] == ".html"
(<4 counts from the end of the string/array)
If you want to see what the extension of a file is, just find the last dot and get the substring after it, e.g. (str/".")[-1]
If you just want to check if the file is of a certain extension, using has_suffix() is a good way, e.g. has_suffix(str, ".html")

in qpython, how do I enter a "return" character

Very basic question. Im trying to use qpython. I can type things in the console but no obvious way to enter a return (or enter)
go to settings->input method select word-based
The console works just like a normally python console. You can use a function if you want to write a script in the console.
There is no way of doing it.
The console will automatically input a break line when the line of code ends so you can continue inputting in the screen without any scroll bars.
For complex code, you should use the editor.
Would a newline character solve your problem?
s = "line 1\n line 2"
print(s)
Should print out
line 1
line 2
If that's what you're looking for? It's called an escape - Python has other ones for tab, etc.

Writing multiline text files in Lua

I would like to know the best way to make my script write something into a file (lets say text.txt) in a way that would always add a line break at the end. When I append text using
file = io.open("test.txt", "a")
file:write("hello")
twice, the file looks like:
hellohello
But I want it to look like:
hello
hello
Unlike print, the new line character isn't added automatically when calling io.write, you can add it yourself:
file:write("hello", "\n")
The easiest way to achieve this would be to include a Newline character sequence every time you call the write method like so: file:write("hello\n") or so: file:write("hello", "\n"). This way, a script such as
file = io.open(test.txt, "a")
file:write("hello", "\n")
file:write("hello", "\n")
would result in the desired output:
hello
hello
There are, however, many other solutions to this (some being more elegant than the others). When outputting text in Java, for example, there are special methods such as BufferedWriter#newLine(), which will do the same thing in a more cleaner fashion. So if your interested in a different way of achieving this, I suggest you read up on the Lua docs for analogous methods/solutions.

How to write couple of lines into a file in C?

I'm having a variable called username and another one called password...
I need to register users into a system, and write it on a file..
My problem is, that the 2nd time or more, it writes the details on the same line..
For example :
in the first time I write for the file, it become something like this :
Amit 123456
but on the second time I'm registering a user, it doesnt go to the next line and keep writing from that spot:
Amit 123456Yosi 125818
where I need the file to be like this :
Amit 123456
Yosi 125818
I mean, I need to make the 2nd or more fprintf to the file go to the next line, and not to start from the specific place...
I've wrote this in the code :
fprintf(file, "%s %s\n", username, password);
though, the '\n'doesnt seems to make the next fprintf go to the next line...
In summery - I need to print to the file every time, on a new line..
on the first print to the file, it'll write on line 1
then on the second print to the file, it'll write on line 2, and not from the continue of line1...
Thanks :)
Had the same thought as the commenters: You may need a \r in there too, depending on your development environment. It could even be that the file viewer you are using is the issue (eg: Notepad.exe on Windows often has trouble with simple line endings)
I'm guessing you're on Windows, you need /r/n
Note that it is very, very bad practice to save passwords, please google how to work with passwords.

Resources