❔ 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
you mean an array of strings?
do you want to have a list of all the names of people with admin privileges?
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
so is this checking for admin privileges or configuring who has them?
it will check to see if the user has adm,in privileges and if they do not, will add them to the system,
so it's configuring who has them
what kind of application is this? console, winforms, wpf, etc
im using visual studio for c# language
visual studio is the IDE, what application are you building?
like what is the purpose of what I'm trying to code?
do you have a GUI?
i do not
so that means it's a console application
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
okay, so how far did you get so far?
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
alright, share what you have so far and describe exactly where you're stuck
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; }
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; }
C
that's not C#...
not even C++, that is indeed straight C
$c
We're partnered with Together C & C++, check them out here: https://discord.gg/vnyVmAE
you probably want to go there
so I did it all wrong, I see
i mean, not necessarily
but if you meant to be writing C# then yes it's a completely different language
i have to use c# for the frontend
like blazor? or what
yeah for blazoer
blazor*
so how did you manage to get so far into writing C without realizing it wasn't C#
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
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
Written interactive course https://learn.microsoft.com/en-us/dotnet/csharp/tour-of-csharp/tutorials/
Videos https://dotnet.microsoft.com/learn/videos
ok
thank you so much for the help! 😄
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.