C
C#13mo ago
zyn

❔ how to create an array to enter user for super admin

I'm trying to wrap my head around how I would use a string of arrays to let the user enter their username which would then grant them admin privilege's
31 Replies
Jimmacle
Jimmacle13mo ago
you mean an array of strings? do you want to have a list of all the names of people with admin privileges?
zyn
zyn13mo ago
yes my bad, an arrary of strings, I want it to be where when you enter a user name itll give the user admin privileges
Jimmacle
Jimmacle13mo ago
so is this checking for admin privileges or configuring who has them?
zyn
zyn13mo ago
it will check to see if the user has adm,in privileges and if they do not, will add them to the system,
Jimmacle
Jimmacle13mo ago
so it's configuring who has them what kind of application is this? console, winforms, wpf, etc
zyn
zyn13mo ago
im using visual studio for c# language
friedice
friedice13mo ago
visual studio is the IDE, what application are you building?
zyn
zyn13mo ago
like what is the purpose of what I'm trying to code?
Jimmacle
Jimmacle13mo ago
do you have a GUI?
zyn
zyn13mo ago
i do not
Jimmacle
Jimmacle13mo ago
so that means it's a console application
zyn
zyn13mo ago
yes, and I have to run it through visual studio so that when a user enters their username, it'll add it to the super admin privilege's through a array of strings
Jimmacle
Jimmacle13mo ago
okay, so how far did you get so far?
zyn
zyn13mo ago
im half way through but I think i did it wrong, I just started using c# so I'm kind of clueless with where i'm going right now
Jimmacle
Jimmacle13mo ago
alright, share what you have so far and describe exactly where you're stuck
zyn
zyn13mo ago
include <stdio.h> #include <stdlib.h> #include <string.h> #define NUMSTR 3 #define BUFFSIZE 100 int main(void) { char words[NUMSTR]; char buffer[BUFFSIZE]; size_t i, count = 0, slen; for (i = 0; i < NUMSTR; i++) { printf("Enter Username: "); if (fgets(buffer, BUFFSIZE, stdin) == NULL) { fprintf(stderr, "Error reading string into buffer.\n"); exit(EXIT_FAILURE); } slen = strlen(buffer); if (slen > 0) { if (buffer[slen-1] == '\n') { buffer[slen-1] = '\0'; } else { printf("Exceeded buffer length of %d.\n", BUFFSIZE); exit(EXIT_FAILURE); } } if (!buffer) { printf("Incorrect User.\n"); exit(EXIT_FAILURE); } words[count] = malloc(strlen(buffer)+1); if (!words[count]) { printf("Cannot allocate memory for string.\n"); exit(EXIT_FAILURE); } strcpy(words[count], buffer); count++; }
printf("\nYour strings:\n"); for (i = 0; i < count; i++) { printf("words[%zu] = %s\n", i, words[i]); free(words[i]); words[i] = NULL; } return 0; }
friedice
friedice13mo ago
C Hmm
Jimmacle
Jimmacle13mo ago
that's not C#... not even C++, that is indeed straight C $c
MODiX
MODiX13mo ago
We're partnered with Together C & C++, check them out here: https://discord.gg/vnyVmAE
Jimmacle
Jimmacle13mo ago
you probably want to go there
zyn
zyn13mo ago
so I did it all wrong, I see
Jimmacle
Jimmacle13mo ago
i mean, not necessarily but if you meant to be writing C# then yes it's a completely different language
zyn
zyn13mo ago
i have to use c# for the frontend
Jimmacle
Jimmacle13mo ago
like blazor? or what
zyn
zyn13mo ago
yeah for blazoer blazor*
Jimmacle
Jimmacle13mo ago
so how did you manage to get so far into writing C without realizing it wasn't C# thonk
zyn
zyn13mo ago
I thought C and c# shared similar coding structures, so i basically just took a shot in the dark at it thinking it would work
Jimmacle
Jimmacle13mo ago
no, they're incompatible (that isn't entirely true but that's out of scope of this project) you should follow a C# tutorial like $helloworld
zyn
zyn13mo ago
ok thank you so much for the help! 😄
Accord
Accord13mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.