Progged programming site

Programming source code, articles, tutorials, links and chat

Archive for the 'C' Category

Print to a file using the fprintf function

This example shows how to Print to a file using the fprintf function in C
#include <stdio.h>
int main()
{
FILE *fp;
int rating = 9;
if (fp = fopen(”d:/website.txt”, “w”))
{
fprintf(fp, “Website: Progged\n”);
fprintf(fp, “Topic: computer programming\n”);
fprintf(fp, “Rating out of 10 : %d \n”,rating );
fclose(fp);
}
else
printf(”Error opening d:/website.txt\n”);
return 0;
}

Bookmark It

Hide Sites

[ Back to top ]

get the computer name

This example will get the computer name
#include <stdio.h>
#include <windows.h>
#include <conio.h>
void main(void)
{
char szBuffer[256];
DWORD dwNameSize=256;
//get the computer name
GetComputerName(szBuffer, &dwNameSize);
//print name
printf(”%s \n”,szBuffer);
getch();
}

Bookmark It

Hide Sites

[ Back to top ]

Constants in C

This C example shows the usage of constants
#include &lt;stdio.h&gt;<br>/*constants for bonus rates and sales*/<br>#define BONUSRATE1 0.1<br>#define BONUSRATE2 0.15<br>#define BONUSRATE3 0.2<br>#define SALES1 2000<br>#define SALES2 5000<br>#define SALES3 10000<p>int main()<br> {<br> int sales;<br> double commission;<br> /*get employees sales*/<br> printf(&quot;Please enter your total sales to the nearest dollar.\n&quot;);<br> scanf(&quot;%d&quot;, &amp;sales);<br> /*calculate employees bonus based on info*/<br> if(sales &lt;=2000)<br> {<br> [...]

[ Back to top ]

Craete a messagebox with C

This C example shows how to create a messagebox
/*works on Visual C++ and LCC win32*/<br>#include &lt;windows.h&gt;<p>int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {<br> MessageBox (NULL, &quot;Hello World&quot; , &quot;Hello&quot;, 0);<br> return 0;<br> } </p>

Bookmark It

Hide Sites

[ Back to top ]

Sponsors