TheBeast32 54 Posting Whiz in Training

Thanks. I had to do data = realloc(data, ++datalen * sizeof(char)). I forgot the "data = ". I just looked it up in my little c reference book.

void* realloc(void* p, size_t size);
Returns pointer to newly-allocated space for an object of size size, initialised, to
minimum of old and new sizes, to existing contents of p (if non-null), or NULL on
error. On success, old object deallocated, otherwise unchanged.

Forgot it returns a pointer :/. I also got rid of the original calloc. I'll do error checking on realloc also. I didn't want to use a static buffer because I don't know how much data the user will enter. I could just ask for the amount of bytes I guess. I thought about leaving room for a null character at the end, but I'm going to be sending it to an smtp server, so does it matter?

TheBeast32 54 Posting Whiz in Training

Hi, I'm making a little program that will send email. I am fine with the sockets, but I keep getting a segmentation fault and I don't know why:$. I'm trying to make a loop that will let the user enter the data for the email, ending with a '.' on its own line (like when using an smtp server). I'm on windows using cygwin.

char *data, ch;
	char newline;
	unsigned int datalen;
	
	data = (char*)calloc(1, sizeof(char));
	newline = 1;
	datalen = 0;
	
	while (1)
	{
		ch = fgetc(stdin);
		realloc(data, ++datalen * sizeof(char));
		*(data + datalen - 1) = ch;
		
		if (newline)
		{
			if (ch == '.')
			{
				realloc(data, ++datalen * sizeof(char));
				*(data + datalen - 1) = '\n';
				break;
			}
			else if (ch != '\n')
			{
				newline = 0;
			}
		}
		else
		{
			if (ch == '\n')
			{
				newline = 1;
			}
		}
	}

Here's my output using gdb:
GNU gdb 5.2.1
Copyright 2002 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "i686-pc-mingw32"...(no debugging symbols found)...
(gdb) run
Starting program: g:\C\MailClient/./mail.exe

Program received signal SIGSEGV, Segmentation fault.
0x7c80a6c2 in _cygheap_end1 ()
(gdb)

I get the segmentation fault after I enter my 13th character.

TheBeast32 54 Posting Whiz in Training

I figured it out after about a bit of searching. For anyone having this same problem: apparently, Cygwin can't use IPv6 by default. I went to http://win6.jp/Cygwin/ and downloaded the files I needed there. I unzipped it into my cygwin directory, and had to replace cygwin1.dll in the bin directory with new-cygwin1.dll.

TheBeast32 54 Posting Whiz in Training

Hi, I installed cygwin recently and wanted to do some network programming with it. Since I have never used unix sockets before, I'm reading Beej's Guide To Network Programming. I took this from section 5.1 and tried to compile it. I get a few errors that I can't figure out :-/.

/*
** showip.c -- show IP addresses for a host given on the command line
*/

#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <arpa/inet.h>

int main(int argc, char *argv[])
{
    struct addrinfo hints, *res, *p;
    int status;
    char ipstr[INET6_ADDRSTRLEN];

    if (argc != 2) {
        fprintf(stderr,"usage: showip hostname\n");
        return 1;
    }

    memset(&hints, 0, sizeof hints);
    hints.ai_family = AF_UNSPEC; // AF_INET or AF_INET6 to force version
    hints.ai_socktype = SOCK_STREAM;

    if ((status = getaddrinfo(argv[1], NULL, &hints, &res)) != 0) {
        fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(status));
        return 2;
    }

    printf("IP addresses for %s:\n\n", argv[1]);

    for(p = res;p != NULL; p = p->ai_next) {
        void *addr;
        char *ipver;

        // get the pointer to the address itself,
        // different fields in IPv4 and IPv6:
        if (p->ai_family == AF_INET) { // IPv4
            struct sockaddr_in *ipv4 = (struct sockaddr_in *)p->ai_addr;
            addr = &(ipv4->sin_addr);
            ipver = "IPv4";
        } else { // IPv6
            struct sockaddr_in6 *ipv6 = (struct sockaddr_in6 *)p->ai_addr;
            addr = &(ipv6->sin6_addr);
            ipver = "IPv6";
        }

        // convert the IP to a string and print it:
        inet_ntop(p->ai_family, addr, ipstr, sizeof ipstr);
        printf("  %s: %s\n", ipver, ipstr);
    }

    freeaddrinfo(res); // free the linked list

    return 0;
}

Here are my errors:
stuff.c: In function …

TheBeast32 54 Posting Whiz in Training

Hi, I'm using GNU MP to get very precise square roots of numbers. I have three questions about my code below.

#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
 
int main(int argc, char *argv[])
{
	mpf_t num, sqrt;
	FILE *out;
	
	mpf_init2(num, 1000000);
	mpf_init2(sqrt, 1000000);
	
	printf("Enter a number to get its square root: ");
	mpf_inp_str(num, stdin, 10);
	
	printf("\nGetting square root...");
	mpf_sqrt(sqrt, num);
	printf("Done!");
	
	out = fopen("output.txt", "w+");
	
	if (!out)
	{
		printf("\nError opening output file!");
		getchar();
		return 1;
	}
	
	printf("\nWriting...");
	mpf_out_str(out, 10, 0, sqrt);
	printf("Done!");
	
	mpf_clear(num);
	mpf_clear(sqrt);
	getchar();
	return 0;
}

1. It writes the output in scientific notation. It's pointless because its just e1 usually. How would I make it so it's not in scientific notation?

2. It doesn't write all 1000000 digits. I should be getting a file that's about 977kb, but it's only 294. How can I fix that?

3. It allocates on the stack, so if I try to do 1 billion digits, I get a stack overflow. How can I make it allocate on the heap?

Hope that's not too much :P. Thanks in advance.
I'm on Windows XP using MinGW.

TheBeast32 54 Posting Whiz in Training

Hi, I'm getting parts for a notebook I'm going to build. I want to do some gaming on it, so I need to know it has reasonable parts. I'm pretty sure the hardware is good for gaming, but I wanted to double check before I buy all of the parts.

Here is the hardware (and OS):

Barebone: OCZ OCZNBIS15DIYA
RAM: OCZ OCZ2MV6674GK
CPU: Intel BX80576T9300
Hard Drive: Seagate ST9320421AS
OS: Windows Vista Home Premium
Wireless Card:	 Intel 4965AGNMM1WB

Are these good parts for gaming or should I find other hardware?

TheBeast32 54 Posting Whiz in Training

Hi, how would I get the temperature and percentage of load for my CPU, GPU, and other things like the hard drive? I'm on Windows XP. Is there something in the Win32 API or what?

TheBeast32 54 Posting Whiz in Training

Thanks.

TheBeast32 54 Posting Whiz in Training

Hi, I was wondering if I got an Intel Core 2 Duo at 2.6ghz, is that 2.6ghz PER core (5.2 ghz total), or is it the total for all of the cores? Thanks in advance.

TheBeast32 54 Posting Whiz in Training

You can just see if AWUTD is y or n and display what you want.

cout<<"Patients Name:"<<Pname<<endl;
cout<<"Patients Age:"<<age<<endl;

cout<<"Patients Current Employer:"<<CEmployer<<endl;

if(AWUTD=='y'||AWUTD=='Y')
{
	cout<<"Work up to date:Yes"<<endl;
}
else if(AWUTD=='n'||AWUTD=='N')
{
	cout<<"Work up to date:No"<<endl;
	cout<<"Specification:"<<AWUTDspecification<<endl;
}

I added the specification if it was no, too.

TheBeast32 54 Posting Whiz in Training

Change

if(AWUTD=='y'||'Y')
	{
		cout<<"Please Specify:"<<endl;
		getline (cin, AWUTDspecification);
	}
	else if (AWUTD=='n'||'N')
	{
		cout<<endl;
	}

to

if(AWUTD=='y'||AWUTD=='Y')
	{
		cout<<"Please Specify:"<<endl;
		getline (cin, AWUTDspecification);
	}
	else if (AWUTD=='n'||AWUTD=='N')
	{
		cout<<endl;
	}

I'm pretty sure that adding ||'Y' to your if means that if the ASCII code for 'Y' is nonzero, then it's true. So it will be true for the first if every time.

TheBeast32 54 Posting Whiz in Training

Nice tutorial Narue. Thanks! That really helped me.

TheBeast32 54 Posting Whiz in Training

Thanks. I'm going to read Narue's guide and see where that brings me. Also, what did you mean by "[1] Unless you want to encode instructions directly with a hex editor... ", Narue?

TheBeast32 54 Posting Whiz in Training

Hi, I want to learn assembly and have looked at tutorials I found on google. It's really freaking complicated, so do any of you know of any good tutorials on assembly? I'm on Windows XP 32 bit with an Intel CPU.

TheBeast32 54 Posting Whiz in Training

Hi, I'm building a gaming computer and wanted to know if my CPU and GPU are good enough for new games like bioshock and fallout 3. I was talking with a friend and he said that if I got what was new a little while ago, it'll still give me good performance at a better price instead of buying the newest thing like an Intel Core i7.

This is the CPU i'm going to get: http://www.newegg.com/Product/Product.aspx?Item=N82E16819115056&Tpk=Intel%20BX80571E7500

This is the GPU: http://www.newegg.com/Product/Product.aspx?Item=N82E16814161252&Tpk=HIS%20Hightech%20H467QT512P

Could I get a very good frame rate with these, or should I upgrade?

TheBeast32 54 Posting Whiz in Training

Hello, my friend's laptop got a very evil virus on it recently. I have scanned it with trend micro internet security multiple times as well as with SpyBot, but it won't die. This virus makes tons of popups appear while browsing. They're mostly ads for antivirus programs and other things. It makes his laptop as slow as death. It takes like ten minutes to boot Windows (Media center edition sp3). He has 2 gb of ddr2 ram and a dual core at 2.4 ghz so I know that's not the problem. Also, when booted into safe mode, it will try to shut down (I just aborted it with "shutdown -a"). When scanning with Trend Micro, it will usually just blue screen. The HijackThis log is attached.

TheBeast32 54 Posting Whiz in Training

No problem.

TheBeast32 54 Posting Whiz in Training
TheBeast32 54 Posting Whiz in Training

Thanks! It works now.

TheBeast32 54 Posting Whiz in Training

Hi, I'm reading the header from bitmaps. When I add up everything in a struct I've made, it comes out to 54 bytes. When I do a sizeof(BHeader), it says it's 56 bytes. It adds two null bytes after the B and the M when I save a header to a file. It's very weird. Please help.

Here's my struct:

typedef struct
{
   unsigned char B;
   unsigned char M;
   unsigned int Size;
   short Reserved1;
   short Reserved2;
   unsigned int Offset;

   unsigned int HeaderSize;
   unsigned int Width;
   unsigned int Height;
   unsigned short Planes;
   unsigned short Bits;
   unsigned int Compression;
   unsigned int ImageSize;
   int XPixelsPerMeter;
   int YPixelsPerMeter;
   unsigned int ColorsInPalette;
   unsigned int ColorImportant;
} BHeader;
TheBeast32 54 Posting Whiz in Training

I absolutely LOVE TrueCrypt! It does exactly what I want it to do. I can just partition my pen drive and put TrueCrypt on one partition (and have another encrypted partition) to use this on other computers. It does more than encrypt whole drives; you can make little files that you can have it mount as disks. Then you can put stuff in them. Thanks!

TheBeast32 54 Posting Whiz in Training

Thanks. Also, I like that google link you posted googleit :)

TheBeast32 54 Posting Whiz in Training

Hi, I want to encrypt my pen drive. Are there any open source or freeware programs that I can use to do this? Being able to decrypt it on any computer running XP without installing any software would be nice. Thanks in advance.

TheBeast32 54 Posting Whiz in Training

What do you have for a CPU?

TheBeast32 54 Posting Whiz in Training

Task manager closed?. I think you have some sort of malware that closed task manager. You need to do something like what cguan_77 said. Booting Linux from a CD and scanning your hard drive would also work.

TheBeast32 54 Posting Whiz in Training

Explorer.exe might have been deleted or just not started. Hit control+alt+del, go to file->New Task (Run...). Type in "explorer" without quotes. If it says "Windows cannot find 'explorer'", then it was deleted by the trojan. You might have to get an install disk to fix that... DO NOT DOWNLOAD PIRATED SOFTWARE!!!! 99.99999999% OF THE TIME IT WILL HAVE SOME KIND OF MALWARE ON IT.

TheBeast32 54 Posting Whiz in Training
TheBeast32 54 Posting Whiz in Training

Hi, I'm trying to use LogonUser. I think I'm doing everything right, but I keep getting this error: 1326 (ERROR_LOGON_FAILURE). I know my user and pass are right.

#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <windows.h>

void GetPassword(char *pass, int maxlen, char hidechar)
{
   char ch;
   int len = 0;

   memset(pass, 0, maxlen);

   while (ch != 13)
   {
      ch = getch();

      switch (ch)
      {
         case '\b':
            memset(pass + len, 0, sizeof(char));

            if (len > 0)
            {
               len--;
               printf("%c%c%c", '\b', ' ', '\b');
            }
            break;

         default:
            if (len < maxlen && (isalnum(ch) || isspace(ch) || ispunct(ch)))
            {
               memset(pass + len, ch, sizeof(char));
               len++;
               printf("%c", hidechar);
            }
            break;
      }
   }

   memset(pass + maxlen, 0, sizeof(char));
}

int main(int argc, char *argv[])
{
   char *pass = (char*)calloc(128, sizeof(char));
   char *user = (char*)calloc(128, sizeof(char));
   PHANDLE h;
   
   printf("Enter your username: ");
   fgets(user, 128, stdin);
   
   printf("Enter your password: ");
   GetPassword(pass, 128, '*');
   
   printf("\nPassword: %s", pass);
   
   if (LogonUser(user, NULL, pass, LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, h))
   {
      printf("\nWindows logon successful!");
   }
   else
   {
      printf("\nWindows logon failed! Error code: %d", GetLastError());
   }
   
   free(pass);
   free(user);
   getch();
}
TheBeast32 54 Posting Whiz in Training

O_o. It was a Windows setting. I had selected to have microphone input from something other than my mic. Sorry I didn't reply last night, I fell asleep :|.

TheBeast32 54 Posting Whiz in Training

Nice link.

TheBeast32 54 Posting Whiz in Training

System() pauses your program doesn't it? I need something that will just execute a program but not wait for it to end to keep going about its business.

TheBeast32 54 Posting Whiz in Training

Hi, whenever I play audio, and the output goes through my speakers, it GOES THROUGH MY MICROPHONE TOO. Like, when I play a song, I monitor the microphone input, and it says it has input when the song is playing. How can I fix this?:?:

TheBeast32 54 Posting Whiz in Training

Hi, I was wondering if there was an alternative to the ShellExecute function of the Windows API; one that is universal on every OS. Is there one?

TheBeast32 54 Posting Whiz in Training

I switched from Dev-C++ to Code::Blocks recently. The interface is awesome. I'm using the MinGW compiler, so there's no difference in compile time (they are using the same compiler). The only thing that I like about Dev-C++ that Code::Blocks doesn't have is DevPaks. They are REALLY easy to add to Dev.

iamthwee commented: Second that. +18
TheBeast32 54 Posting Whiz in Training

If you have never deleted temporary files with a program like CCleaner, do it! I recently cleared files from a friend's computer. He had never done that. It made his computer much faster (he had like 2GB of temp files!).

TheBeast32 54 Posting Whiz in Training

You might need more RAM. Do you know how much you have? If there isn't a lot, Windows will write to a page/swap file on the hard drive. This greatly reduces performance.

TheBeast32 54 Posting Whiz in Training

Bubble sorts are very easy to make. Just Google "bubble sort algorithm".

TheBeast32 54 Posting Whiz in Training

You could use a proxy that's in Turkey. Other than that, you can't just change your IP to a Turkish one.

TheBeast32 54 Posting Whiz in Training

This is a very complex sort. There's pseudocode on Wikipedia http://en.wikipedia.org/wiki/Heap_sort.

TheBeast32 54 Posting Whiz in Training

Hi, I'm making a program that will get input from a user's microphone, send it to another user with a socket, and play it. It's like a VoIP thing. I can send data using a socket, but I have no idea how to get input from a microphone or play it back. Thanks in advance.:P

TheBeast32 54 Posting Whiz in Training

Those are idle temperatures right?

TheBeast32 54 Posting Whiz in Training

No, it just seemed a little bit hotter than it should be. It idles at 46-48.

TheBeast32 54 Posting Whiz in Training

Hi, I have a P4 Prescott @ 3.2 Ghz. I have an 80 mm case fan and my cpu fan is a Thermaltake TR2 M12 A4012-02. Is this enough for my CPU, or do I need some more fans? Also, there are vents on one side of my case if that means anything.

TheBeast32 54 Posting Whiz in Training

WOOT! I got a case fan and put new thermal compound on my CPU and it is a lot cooler! It went down by almost 15 degrees Celsius. I'll play a game and see how hot it gets.

TheBeast32 54 Posting Whiz in Training

Thanks for your help. I'll be sure to get some thermal compound.

TheBeast32 54 Posting Whiz in Training

The thermal compound on my fan was new. I had just taken the fan out of the box. I think I'll get some. Would it survive until like next weekend?

TheBeast32 54 Posting Whiz in Training

There was some thermal compound on the fan; is that not enough?

TheBeast32 54 Posting Whiz in Training

Hi, I just replaced my 2.4 Ghz Intel Celeron CPU with a P4 Prescott at 3.2 ghz like 2 hours ago. It idles at like 48 degrees Celsius. I played half-life 2 for a bit and it went up to like 60-62. I didn't put any thermal crap on it. I have a new fan that says it supports up to 3.6 Ghz. Is this normal for my CPU, or if not what should I do?

The fan is a Thermaltake TR-M12 for socket 478

TheBeast32 54 Posting Whiz in Training

Thanks, I'll see if I can do what you said. I just have to download the distro because it's like 700 mb.

TheBeast32 54 Posting Whiz in Training

Hi, I'm going to install CrunchBang Linux on my 2GB pen drive. I was just wondering about the way it saves stuff. Do you have to back up and restore your data and settings every time you shutdown and boot like when using Damn Small Linux for everything to be saved?