recursively opening/creating files using c

Most of the day was spent between classes and the afternoon was spent listening to talks at the dept. of physics, as part of the in-house symposium this weekend. Most of them went over my head and I decided to get out of the air conditioned lecture hall before I start drooling or dozing off, to save what little face I have left. Having had a heavy lunch, I finally got some coffee and kicked off my boots, getting back on the numerical methods in programming assignment. A part of it is to plot the legendre functions of degrees (0,5) in the interval (-1,1). For this, I thought I'd have to iteratively open files and write the the function values to different ones. And for this I needed to know how to create files iteratively. Blindly, I tried
in_ptr = fopen("file_%d"+i,"w");
where i was the variable I was iterating over. And it worked, no compilation error, no execution error. The results however were interesting! It created files names file_, ile_, le_, e_, and _. I kid you not! Here's the code, compile and execute it yourself, if you don't believe me! In reality, the actual solution i found on stackoverflow worked like a charm.

Popular posts from this blog

Animation using GNUPlot

Arxiv author affiliations using Python

Thoughts on the National Deep Tech Startup Policy