Skip to main content
replaced http://cs50.stackexchange.com/ with https://cs50.stackexchange.com/
Source Link

You have FIVE major problems that will break your code, but for now I'll only tell you about the first one, which is causing the seg fault. This one:

argv11 is a string (sometimes a string with length 1, but still a string) and isdigit() is meant to be used with single chars, not strings:

if(!(isdigit(argv[1])))
    return 5;

After fixing that, your program will start, but enter an infinite loop. (EDIT: your comment suggests you've fixed it, so I'll tackle the next problem)


EDIT: explaining the integer overflow:

bi.biHeight can be positive or negative, see MSDN: https://msdn.microsoft.com/en-us/library/windows/desktop/dd183376(v=vs.85).aspx

Now look at:

bi.biSizeImage = (bi.biWidth * sizeof(RGBTRIPLE) + padding) * bi.biHeight;

See that "bi.biSizeImage" up there has a chance of being negative, because the variable "bi.biHeight" can also be negative.

As the error you're receiving indicates unsigned integer overflow, let's guess that "bi.biSizeImage" is an unsigned long. An unsigned long cannot represent negative numbers, so, long story short to not burden you with low level details: via arithmetic conversion (you can read about it herehere) bi.biHeight will become a huge positive integer instead of a negative integer.

Then (bi.biWidth * sizeof(RGBTRIPLE) + padding) * bi.biHeight; will be some number multiplied by this now huge number of bi.biHeight, and that will be too big to fit even an unsigned long.

TL;DR: you need to use the absolute value of bi.biHeight.


After fixing that, you'll get a problem regarding skipping the wrong padding. (EDIT: you've solved that by yourself now. Congratulations.)


After fixing that, you'll get a problem related to not using fseek() to go back to the start of the line after the iteration of a certain loop.
EDIT: you've almost solved that by yourself now

But you're setting "int seek" initially to zero, but the image doesn't start at zero! It starts only after the headers, right? So if you use seek = 0, you'll be going all the way back to the beginning of inptr and writing it's headers to the outfile all over again most likely. Your initial value for seek must account for the header. (hint: maybe use ftell() ? ) –


I think that sums it all up.

You have FIVE major problems that will break your code, but for now I'll only tell you about the first one, which is causing the seg fault. This one:

argv1 is a string (sometimes a string with length 1, but still a string) and isdigit() is meant to be used with single chars, not strings:

if(!(isdigit(argv[1])))
    return 5;

After fixing that, your program will start, but enter an infinite loop. (EDIT: your comment suggests you've fixed it, so I'll tackle the next problem)


EDIT: explaining the integer overflow:

bi.biHeight can be positive or negative, see MSDN: https://msdn.microsoft.com/en-us/library/windows/desktop/dd183376(v=vs.85).aspx

Now look at:

bi.biSizeImage = (bi.biWidth * sizeof(RGBTRIPLE) + padding) * bi.biHeight;

See that "bi.biSizeImage" up there has a chance of being negative, because the variable "bi.biHeight" can also be negative.

As the error you're receiving indicates unsigned integer overflow, let's guess that "bi.biSizeImage" is an unsigned long. An unsigned long cannot represent negative numbers, so, long story short to not burden you with low level details: via arithmetic conversion (you can read about it here) bi.biHeight will become a huge positive integer instead of a negative integer.

Then (bi.biWidth * sizeof(RGBTRIPLE) + padding) * bi.biHeight; will be some number multiplied by this now huge number of bi.biHeight, and that will be too big to fit even an unsigned long.

TL;DR: you need to use the absolute value of bi.biHeight.


After fixing that, you'll get a problem regarding skipping the wrong padding. (EDIT: you've solved that by yourself now. Congratulations.)


After fixing that, you'll get a problem related to not using fseek() to go back to the start of the line after the iteration of a certain loop.
EDIT: you've almost solved that by yourself now

But you're setting "int seek" initially to zero, but the image doesn't start at zero! It starts only after the headers, right? So if you use seek = 0, you'll be going all the way back to the beginning of inptr and writing it's headers to the outfile all over again most likely. Your initial value for seek must account for the header. (hint: maybe use ftell() ? ) –


I think that sums it all up.

You have FIVE major problems that will break your code, but for now I'll only tell you about the first one, which is causing the seg fault. This one:

argv1 is a string (sometimes a string with length 1, but still a string) and isdigit() is meant to be used with single chars, not strings:

if(!(isdigit(argv[1])))
    return 5;

After fixing that, your program will start, but enter an infinite loop. (EDIT: your comment suggests you've fixed it, so I'll tackle the next problem)


EDIT: explaining the integer overflow:

bi.biHeight can be positive or negative, see MSDN: https://msdn.microsoft.com/en-us/library/windows/desktop/dd183376(v=vs.85).aspx

Now look at:

bi.biSizeImage = (bi.biWidth * sizeof(RGBTRIPLE) + padding) * bi.biHeight;

See that "bi.biSizeImage" up there has a chance of being negative, because the variable "bi.biHeight" can also be negative.

As the error you're receiving indicates unsigned integer overflow, let's guess that "bi.biSizeImage" is an unsigned long. An unsigned long cannot represent negative numbers, so, long story short to not burden you with low level details: via arithmetic conversion (you can read about it here) bi.biHeight will become a huge positive integer instead of a negative integer.

Then (bi.biWidth * sizeof(RGBTRIPLE) + padding) * bi.biHeight; will be some number multiplied by this now huge number of bi.biHeight, and that will be too big to fit even an unsigned long.

TL;DR: you need to use the absolute value of bi.biHeight.


After fixing that, you'll get a problem regarding skipping the wrong padding. (EDIT: you've solved that by yourself now. Congratulations.)


After fixing that, you'll get a problem related to not using fseek() to go back to the start of the line after the iteration of a certain loop.
EDIT: you've almost solved that by yourself now

But you're setting "int seek" initially to zero, but the image doesn't start at zero! It starts only after the headers, right? So if you use seek = 0, you'll be going all the way back to the beginning of inptr and writing it's headers to the outfile all over again most likely. Your initial value for seek must account for the header. (hint: maybe use ftell() ? ) –


I think that sums it all up.

added 363 characters in body
Source Link
Yuri Laguardia
  • 2.6k
  • 1
  • 10
  • 17

You have FIVE major problems that will break your code, but for now I'll only tell you about the first one, which is causing the seg fault. This one:

argv1 is a string (sometimes a string with length 1, but still a string) and isdigit() is meant to be used with single chars, not strings:

if(!(isdigit(argv[1])))
    return 5;

After fixing that, your program will start, but enter an infinite loop. (EDIT: your comment suggests you've fixed it, so I'll tackle the next problem)


EDIT: explaining the integer overflow:

bi.biHeight can be positive or negative, see MSDN: https://msdn.microsoft.com/en-us/library/windows/desktop/dd183376(v=vs.85).aspx

Now look at:

bi.biSizeImage = (bi.biWidth * sizeof(RGBTRIPLE) + padding) * bi.biHeight;

See that "bi.biSizeImage" up there has a chance of being negative, because the variable "bi.biHeight" can also be negative.

As the error you're receiving indicates unsigned integer overflow, let's guess that "bi.biSizeImage" is an unsigned long. An unsigned long cannot represent negative numbers, so, long story short to not burden you with low level details: via arithmetic conversion (you can read about it here) bi.biHeight will become a huge positive integer instead of a negative integer.

Then (bi.biWidth * sizeof(RGBTRIPLE) + padding) * bi.biHeight; will be some number multiplied by this now huge number of bi.biHeight, and that will be too big to fit even an unsigned long.

TL;DR: you need to use the absolute value of bi.biHeight.


After fixing that, you'll get a problem regarding skipping the wrong padding. (EDIT: you've solved that by yourself now. Congratulations.)


After fixing that, you'll get a problem related to not using fseek() to go back to the start of the line after the iteration of a certain loop. (ask another question here later
EDIT: you've almost solved that by yourself now

But you're setting "int seek" initially to zero, but the image doesn't start at zero! It starts only after the headers, right? So if you don't manageuse seek = 0, you'll be going all the way back to solvethe beginning of inptr and writing it's headers to the outfile all over again most likely. Your initial value for seek must account for the header. (hint: maybe use ftell() ? ) –

 

I think that sums it all up.

You have FIVE major problems that will break your code, but for now I'll only tell you about the first one, which is causing the seg fault. This one:

argv1 is a string (sometimes a string with length 1, but still a string) and isdigit() is meant to be used with single chars, not strings:

if(!(isdigit(argv[1])))
    return 5;

After fixing that, your program will start, but enter an infinite loop. (EDIT: your comment suggests you've fixed it, so I'll tackle the next problem)


EDIT: explaining the integer overflow:

bi.biHeight can be positive or negative, see MSDN: https://msdn.microsoft.com/en-us/library/windows/desktop/dd183376(v=vs.85).aspx

Now look at:

bi.biSizeImage = (bi.biWidth * sizeof(RGBTRIPLE) + padding) * bi.biHeight;

See that "bi.biSizeImage" up there has a chance of being negative, because the variable "bi.biHeight" can also be negative.

As the error you're receiving indicates unsigned integer overflow, let's guess that "bi.biSizeImage" is an unsigned long. An unsigned long cannot represent negative numbers, so, long story short to not burden you with low level details: via arithmetic conversion (you can read about it here) bi.biHeight will become a huge positive integer instead of a negative integer.

Then (bi.biWidth * sizeof(RGBTRIPLE) + padding) * bi.biHeight; will be some number multiplied by this now huge number of bi.biHeight, and that will be too big to fit even an unsigned long.

TL;DR: you need to use the absolute value of bi.biHeight.


After fixing that, you'll get a problem regarding skipping the wrong padding. (EDIT: you've solved that by yourself now. Congratulations.)


After fixing that, you'll get a problem related to not using fseek() to go back to the start of the line after the iteration of a certain loop. (ask another question here later if you don't manage to solve.)

I think that sums it all up.

You have FIVE major problems that will break your code, but for now I'll only tell you about the first one, which is causing the seg fault. This one:

argv1 is a string (sometimes a string with length 1, but still a string) and isdigit() is meant to be used with single chars, not strings:

if(!(isdigit(argv[1])))
    return 5;

After fixing that, your program will start, but enter an infinite loop. (EDIT: your comment suggests you've fixed it, so I'll tackle the next problem)


EDIT: explaining the integer overflow:

bi.biHeight can be positive or negative, see MSDN: https://msdn.microsoft.com/en-us/library/windows/desktop/dd183376(v=vs.85).aspx

Now look at:

bi.biSizeImage = (bi.biWidth * sizeof(RGBTRIPLE) + padding) * bi.biHeight;

See that "bi.biSizeImage" up there has a chance of being negative, because the variable "bi.biHeight" can also be negative.

As the error you're receiving indicates unsigned integer overflow, let's guess that "bi.biSizeImage" is an unsigned long. An unsigned long cannot represent negative numbers, so, long story short to not burden you with low level details: via arithmetic conversion (you can read about it here) bi.biHeight will become a huge positive integer instead of a negative integer.

Then (bi.biWidth * sizeof(RGBTRIPLE) + padding) * bi.biHeight; will be some number multiplied by this now huge number of bi.biHeight, and that will be too big to fit even an unsigned long.

TL;DR: you need to use the absolute value of bi.biHeight.


After fixing that, you'll get a problem regarding skipping the wrong padding. (EDIT: you've solved that by yourself now. Congratulations.)


After fixing that, you'll get a problem related to not using fseek() to go back to the start of the line after the iteration of a certain loop.
EDIT: you've almost solved that by yourself now

But you're setting "int seek" initially to zero, but the image doesn't start at zero! It starts only after the headers, right? So if you use seek = 0, you'll be going all the way back to the beginning of inptr and writing it's headers to the outfile all over again most likely. Your initial value for seek must account for the header. (hint: maybe use ftell() ? ) –

 

I think that sums it all up.

added 4 characters in body
Source Link
Yuri Laguardia
  • 2.6k
  • 1
  • 10
  • 17

You have FIVE major problems that will break your code, but for now I'll only tell you about the first one, which is causing the seg fault. This one:

argv1 is a string (sometimes a string with length 1, but still a string) and isdigit() is meant to be used with single chars, not strings:

if(!(isdigit(argv[1])))
    return 5;

After fixing that, your program will start, but enter an infinite loop. (EDIT: your comment suggests you've fixed it, so I'll tackle the next problem)


EDIT: explaining the integer overflow:

bi.biHeight can be positive or negative, see MSDN: https://msdn.microsoft.com/en-us/library/windows/desktop/dd183376(v=vs.85).aspx

Now look at:

bi.biSizeImage = (bi.biWidth * sizeof(RGBTRIPLE) + padding) * bi.biHeight;

See that "bi.biSizeImage" up there has a chance of being negative, because the variable "bi.biHeight" can also be negative.

As the error you're receiving indicates unsigned integer overflow, let's guess that "bi.biSizeImage" is an unsigned long. An unsigned long cannot represent negative numbers, so, long story short to not burden you with low level details: via arithmetic conversion (you can read about it here) bi.biHeight will become a huge positive integer instead of a negative integer.

Then (bi.biWidth * sizeof(RGBTRIPLE) + padding) * bi.biHeight; will be some number multiplied by this now huge number of bi.biHeight, and that will be too big to fit even an unsigned long.

TL;DR: you need to use the absolute value of bi.biHeight.


After fixing that, you'll get a problem regarding skipping the wrong padding. (ask another question here later if you don't manage to solve.EDIT: you've solved that by yourself now. Congratulations.)

 

After fixing that, you'll get a problem related to not using fseek() to go back to the start of the line after the iteration of a certain loop. (ask another question here later if you don't manage to solve.)

I think that sums it all up.

You have FIVE major problems that will break your code, but for now I'll only tell you about the first one, which is causing the seg fault. This one:

argv1 is a string (sometimes a string with length 1, but still a string) and isdigit() is meant to be used with single chars, not strings:

if(!(isdigit(argv[1])))
    return 5;

After fixing that, your program will start, but enter an infinite loop. (EDIT: your comment suggests you've fixed it, so I'll tackle the next problem)


EDIT: explaining the integer overflow:

bi.biHeight can be positive or negative, see MSDN: https://msdn.microsoft.com/en-us/library/windows/desktop/dd183376(v=vs.85).aspx

Now look at:

bi.biSizeImage = (bi.biWidth * sizeof(RGBTRIPLE) + padding) * bi.biHeight;

See that "bi.biSizeImage" up there has a chance of being negative, because the variable "bi.biHeight" can also be negative.

As the error you're receiving indicates unsigned integer overflow, let's guess that "bi.biSizeImage" is an unsigned long. An unsigned long cannot represent negative numbers, so, long story short to not burden you with low level details: via arithmetic conversion (you can read about it here) bi.biHeight will become a huge positive integer instead of a negative integer.

Then (bi.biWidth * sizeof(RGBTRIPLE) + padding) * bi.biHeight; will be some number multiplied by this now huge number of bi.biHeight, and that will be too big to fit even an unsigned long.

TL;DR: you need to use the absolute value of bi.biHeight.


After fixing that, you'll get a problem regarding skipping the wrong padding. (ask another question here later if you don't manage to solve.)

After fixing that, you'll get a problem related to not using fseek() to go back to the start of the line after the iteration of a certain loop. (ask another question here later if you don't manage to solve.)

I think that sums it all up.

You have FIVE major problems that will break your code, but for now I'll only tell you about the first one, which is causing the seg fault. This one:

argv1 is a string (sometimes a string with length 1, but still a string) and isdigit() is meant to be used with single chars, not strings:

if(!(isdigit(argv[1])))
    return 5;

After fixing that, your program will start, but enter an infinite loop. (EDIT: your comment suggests you've fixed it, so I'll tackle the next problem)


EDIT: explaining the integer overflow:

bi.biHeight can be positive or negative, see MSDN: https://msdn.microsoft.com/en-us/library/windows/desktop/dd183376(v=vs.85).aspx

Now look at:

bi.biSizeImage = (bi.biWidth * sizeof(RGBTRIPLE) + padding) * bi.biHeight;

See that "bi.biSizeImage" up there has a chance of being negative, because the variable "bi.biHeight" can also be negative.

As the error you're receiving indicates unsigned integer overflow, let's guess that "bi.biSizeImage" is an unsigned long. An unsigned long cannot represent negative numbers, so, long story short to not burden you with low level details: via arithmetic conversion (you can read about it here) bi.biHeight will become a huge positive integer instead of a negative integer.

Then (bi.biWidth * sizeof(RGBTRIPLE) + padding) * bi.biHeight; will be some number multiplied by this now huge number of bi.biHeight, and that will be too big to fit even an unsigned long.

TL;DR: you need to use the absolute value of bi.biHeight.


After fixing that, you'll get a problem regarding skipping the wrong padding. (EDIT: you've solved that by yourself now. Congratulations.)

 

After fixing that, you'll get a problem related to not using fseek() to go back to the start of the line after the iteration of a certain loop. (ask another question here later if you don't manage to solve.)

I think that sums it all up.

added 30 characters in body
Source Link
Yuri Laguardia
  • 2.6k
  • 1
  • 10
  • 17
Loading
added 1022 characters in body
Source Link
Yuri Laguardia
  • 2.6k
  • 1
  • 10
  • 17
Loading
Source Link
Yuri Laguardia
  • 2.6k
  • 1
  • 10
  • 17
Loading