How to Combine and work with data from two files? - file

VERY new to Python. I was programming in RPG and COBOL professionally decades ago so I have a programming background but haven't for years and now learning Python ......
I have two simple CSV files I open and work in. Then I want to combine the results and do more but it doesn't seem to let me.
(1) Currently I have defined a function (PROFDATA) to open first file (simple file of students marks from a professor). I access data and do some calculations and manipulations. Works great!
(2) I next define another function (TADATA) open the second file which has more marks for the students. I access do stuff and when I print, it gives me what I want from that file.
I want to combine my results from both files and then do more things but I don't seem to know best method. I know keeping them as FUNCTIONS means that the variables aren't available elsewhere.
Should I be writing data that I need from each file to a 3rd file?
Not sure of the best approach. Sorry up front as I know this must be a big time beginner question.
Tami

Related

How to store data from a .TIFF file to then modify it with my C program

I know few about this and i'm trying to keep building upon it. My goal is to do image stacking with some criteria using C language, as i came upon some cool ideas i think i should be capable of doing with my photos. My C background should be enough to understand what i may need. That being said...
So far i've learned how to read an existing .TIFF file and save it into a char array. The problem is i don't know in which way its data is contained so that i can then be able to analize individual pixels and modify them, or build another .TIFF file from data i previously read.
I've read some things about (a so called) libtiff.h which may be usefull but i can't find where to get it, neither how to install it.
Does anyone know how a .TIFF file data is stored so that i can read it and apply changes to it?
Also,
Does anyone have any experience with handling image files and editing in C? Where did you learn it from?
Do you know of any place i could search for information/tutorials?
Any help will be very usefull,
Thanks in advance.
You can do an enormous amount of very sophisticated processing on TIFFs, or any one of 190+ other formats with ImageMagick without any need to understand TIFF format or write any C. Try searching on Stack Overflow for [imagemagick]
If you want to do processing yourself, consider https://cimg.eu
Another option might be to convert your TIFFs to NetPBM which is much, much simpler to read and write in C. That would be as follows with ImageMagick:
magick INPUT.TIFF -compress none OUTPUT.PPM

How to change the name of a file in C?

Currently, I am taking some measurements and saving the data in a txt file. My C program is supposed to run without interruptions and it writes several files, one after the other. On another machine I want to have a routine to copy the files that are done writing and are ready to be analysed. To distinguish between them, I want the files to be written with a tag, something like: *.part.txt.
I was thinking of using the rename() function. My problem is, I do not know how to easily change the string from *.part.txt to just *.txt.
This would be much easier using Python, but I have to use C for this one and sadly, I lack the necessary experience to solve this by myself.

Storing data in a struct or txt file?

Im making an mock ATM program for practice and was wondering is it better
to
store someones account information in a struct on another file and have each users information on that
Have it all in a txt file and just read it while making an algorithm to grab what you need based on pin location ?
right now iv just made a pin list in a text file which counts and stores the data into an array which i check which then opens an account based on that user input ect ect.
i can see both working but was just wondering whats the proper process for stuff such as this ?
It may depend on your operating system and the language/development tools you use as some will have libraries allowing easy access to structured data in a standardized format as pointed out above.
Text files are rarely the way to go long term since you will have to write all the code yourself, not only creating a lot of work but opening yourself to bugs and potential security issues. If you can use a library, a lot of that work is already done for you.

I need help creating my first project [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I've been learning C for the past 4 months and I thought of giving my self a little challenge to motivate my self, so now i'm looking forward to do a little project on how to manipulate wave format files, but i have few little problems before i start doing this project.
First the program which i will create is simple application that allows the user to open his wave file, do few tricks that are listed in a menu like cutting, reversing, resizing and save his file at the end.
the menu will be lunched this way :
File
Open : asks the user to open a file, if there is one already ope, it suggest to save it.
Save as : Saving the file with a name given by the user (if the user doesn't give any name, a default name will be used) and giving
the user the ability to save his file in one of the formats
WAVE 8 bits Mono 11.025 kHz
WAVE 16 bits Stereo 44,1 kHz
WAVE 24 bits 5.1 192 kHz
MIDI .. ect
Info : shows the information about the audio file (name of the file, type of the file, length of the file in hh:mm:ss)
Exit : exiting the application ; if the file wasn't saved, the application suggest to save it.
Editing
Reverse : reversing the audio file.
Cut : cutting the audio file at a chosen moment as a start point and an end moment as a end point.
Resize : making the audio file play faster or slower (for example, play 2 times faster or slower)
… ect
1 - I want to create a library like "menu_f.h" that contain the menus functions, making a new menu, adding a function or a sub-menu and include it later in my program, but i have no idea what should i write inside the code file of menu_f.h so i can be able to include it later on into the main program.
2 - I want learn how to create a make file because i don't want the user to link the libraries or anything complicated, i just want him to make the program and run it, or if its possible, run it directly
3 - If you have in mind any other idea of functions that would do some cool stuffs, I'll be glad to hear them.
Ask yourself, what do you want more out of this? Practice with C? or a way to modify .wav files? If you want C practice, by all means continue on, but I think if you're really looking for a way to modify a .wav file you'll be able to find plenty of solutions in higher level languages.
1) Its as simple as making your header file ( menu_f.h) and associated c file (menu_f.c). Follow a tutorial to find out what kind of code goes in what file ie: https://www.tutorialspoint.com/cprogramming/c_header_files.htm
2) Google some about make first, then check out the tool "automake". Again, make sure you're honest with yourself about what you're trying to accomplish. (You're getting practice in C, most likely there is better software already out there).
3) It might be interesting to try do perform a FFT (Fast Fourier Transform) of the .wav file. The math is pretty hardcore, but the concept is understandable, and you can borrow code from a library that already implements it (https://sourceforge.net/projects/kissfft/).

C theory/general practice related to "splitting" the system into x number of source files

I have a quick question when programming in C. I am writing a simple application in C as the title suggests but i find myself defining rather large functions in separate source files so it makes maintenance and debugging much easier but my question is is there a standard X amount of lines in a c source file before you should "split" it up into multiple files or is it very dependant on the system/functions in question.
Say for example i have 20 source files with 1 function in each say the functions are somewhat related but they all do different things (e.g. they all manipulate the same struct in some way) should you in theory have these 20 files, or 1 larger file with 20 functions and keep the modification of X structure in the same file?
My idea is the more "split" the better/easier the coding becomes, but then again im quite new to C.
Any input will be appreciated.
Cheers,
Chris.
It makes sense to put code related to the same conceptional area together. If you have functions which work on matrices for example, it would seem to make sense to have a file called matrices.c within which, there are X number of matrix functions. A function called render would obviously not belong there.
Yet if the number of matrix function were to grow huge, it started to feel wrong to shove them all into a single file. Under such a situation I would look for sub-categories and create separate files for each, e.g 2d_matrix.c, 3d_matrix.c, etc.
As for the number of functions you place in a file before you recategorize it, that's is up to personal choice and sometimes development rules of the team you work for.
The same consideration sometimes applies to the size of a function. One team I have worked for would not allow code which is over two screens high, feeling that such code should be broken up into a number of smaller functions which would make the code more readable.
To me, structure your code in a way that makes sense. Keep related code together and be sensible with sizes of functions, number of functions in a file (both too few or too many).
The larger a function gets, the more easy it is to accidentally break it.
The more code you shove in one file, the more likely it will be for other people to be a little sloppy and shove more, and possibly unrelated code in the same file.
Splitting up of a file is not function/system dependant. That entirely depends on the programmer. I have seen 1000-1500 or even more lines of code in a single C file. Keeping twenty functions in a same file makes sense if they are not very different from each other. However if you split the functions among the files, make sure that you write the Makefile properly when compiling them. The phrase " the more split, the easier coding becomes" is debatable.
I liked alk's answer in the closed duplicate: If you follow an object oriented style in C, i.e. use structures and operations on them, the files separate quite naturally in the same way as they would in C++. Operations on the same data types, together forming a "poor man's class", go together.

Resources