Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Global Variable and Compiler issue

Global Variable and Compiler issue

Global Variable and Compiler issue


I have no knowledge of C but have been asked to modify a file to carry out a task. What I am trying to do is to use a global variable to replace a particular variable in a config file.

Under the include section I have added the following:

int globalvar;

In the main() section I have:

globalvar = 100;

and in the function block I have:

if (my criteria are met)
    char strBuf[16];
    int len;

    sprintf(strBuf, "%d", gcount);
    len = strlen(strBuf);  

When I try to compile this, using the Solaris cc compiler, I am getting the following error:

line 129: syntax error before or at: char
line 132: undefined symbol: strBuf
line 132: warning: improper pointer/integer combination: arg #1
undefined symbol: len

I have tried replacing the incrementing of globalvar with:

   int localvar = globalvar + 1;

and this compiles fine and outputs the globalvar incremented by 1 for each instance. However I want to be able to increment the globalvar each time the condition is met so the number should increment over and over.

Can anyone please advise on what I am doing wrong.




RE: Global Variable and Compiler issue

What's your "function block"?
If your function is in a separate file (module), you must declare globalvar as an external variable in this module:


extern int globalvar;

RE: Global Variable and Compiler issue

Just so we see EXACTLY what you're working with, please copy and paste your code with your question(s).


RE: Global Variable and Compiler issue

You're working in C: not C++.  All declarations have to be before code.


    char strBuf[16];
    int len;
    /* No executable statements before this unless they are assignments */

    sprintf(strBuf, "%d", gcount);
    len = strlen(strBuf);  

RE: Global Variable and Compiler issue


Thanks for your help.
What you said corrected the problem and its working now.
Cant believe something so simple could cause all the issues I had.



Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close