Hello, I am working on a new screen for a program used by the U.S. Department of Labor. I am getting a signal SEGV (access to address exceeded protections) when I try to excute the command snprintf(rowh[1] + 30, 4, "%4d", baseyr + 1);. The string I am trying to copy into is declared char *rowh[] = {"Percent average annual wage from prior year =>","Maximum taxable wage base for YYYY =>","Percent average annual wage from second prior year =>"};

The snprintf statement is attempting to overwrite the YYYY in the second string declared in the rowh array. The base year + 1 value is 2014, which is what I want to appear instead of YYYY. Since the string is declared, and I am attempting to overwrite a portion of that string, I do not understand why I am getting a stack overflow, which is what this error indicates is happening. I have tried using the command sprintf(rowh[1], "%4d", baseyr + 1); instead, but I get the same error. The screen this code is in is a standalone program, and does not have that many variables declared, so there is not any good reason for it to run out of memory. Any help with this problem is appreciated.

I see a few issues.

  1. If the new string is longer than the declaration, overflow.
  2. The way you declared the string is not a variable but a fixed string. You wrote you didn't declare a variable then you tried to treat it as a variable. You can't have it both ways.

Go ahead and declare the variable string so it's writeable.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.