Ask coding questions

← Back to all posts
Please can you help me
aadiJain1 (0)

I create a function in C programming language for removing the start and last curly braces form json and store that data in variable but i am getting error that my function is not working correctly please can you help me

xxpertHacker (390)

This is a potentially dangerous warning, depending on what you do.

Either create a char buffer and strcpy data into main, or use a pointer to constants: char const * const main = data;

Also that function seems to be accepting a char const (*)[1000], not a char const *, but I guess that's more general.

Just use char const *, not char* on main, or use char * on data, they should match, that's all.

Coder100 (8720)

There are no errors, those are just warnings. You can safely ignore warnings.

aadiJain1 (0)

@Coder100 i see that after warning my code is working but i want that my output will be without {} in the end and in the starting

Coder100 (8720)


smh this isn't a for loop

aadiJain1 (0)

@Coder100 what is the error or problem in this please can you tell me

Coder100 (8720)

you have to do < sizeof(main) iirc @aadiJain1

aadiJain1 (0)

@Coder100 so how can i read char by char

Highwayman (1358)

Nuuu you do i < strlen(main) also why are you using main as a variable name and also the original for loop was fine, the only problem is that it’s actually a pointer to constant memory, so the characters aren’t going to change. You need to use strcpy or memcpy in order to make a new, mutable string.

@aadiJain1 @Coder100

aadiJain1 (0)

@Highwayman so i have to do that i have to use change the name of variable and also use strcpy

Highwayman (1358)

Yes. The way your loop was originally checking for the end of the string was fine too though, I don’t want to discourage that [email protected]

fuzzyastrocat (767)

@Coder100 @aadiJain1 @Highwayman I'd actually encourage that kind of loop in this situation, it's more representative of what's actually going on.

Highwayman (1358)

You mean the original? I agree :D

CSharpIsGud (599)

@Coder100 No, you cannot safely ignore every warning. Definitely not in C or C++. It might look like nonsense and maybe still compile fine but usually if you're getting a warning you are doing something wrong.
That something can possibly just be redundant logic, or it could be a mistake with something such as pointer arithmetic, which in that case can cause your program to A. Segmentation Fault, B. Work fine in some cases but randomly segfault in others or C. Doesn't segfault, but does nothing or something very different from what you wanted it to do. There's a reason you see OS Development tutorials turning on every single warning.