Assigning the variable as '\ r' instead of taking the value received from the user?
I have a function with some variables defined in it. Variables were defined as static at the top. One of the variables will be taken from the user and an element of array will be equalized to this variable.
like this:
static char[] assign_this_array = new char[1];
static char get_from_user;
static void whatever()
{
Console.Write("enter");
get_from_user = Convert.ToChar(Console.Read());
assign_this_array[0] = get_from_user;
}
When the function is first called, it takes the value from the user and makes the assignment. But the second and other times it does not get from the user. When I debugged, I saw that it did not get from the user. When I looked at the get_from_user variable, I saw that '\ r' was assigned. Why is this happening and is there a solution?
See also questions close to this topic
-
Convert CSV file data from any language to English in C#
I would like to convert CSV file data from multi languages such as Spanish, Russian, European etc to English language in C# program.
Convert all characters like Ó, É to English characters.
Thanks.
-
I get an error when solving this problem, How can I fix?
I am trying to solve the Climbstairs problem but in reverse, where I want to know the number of steps I have to take to go down.
I can go down 1, 2, 3 or 4 steps at the same time. That is, if I am at step i, I can go down to step i - a for any of the values 1, 2, 3 or 4 of a.
I have the following code but I don't know what happens:
I got this error: System.IndexOutOfRangeException in this line:
steps[i] += steps[i - a];
Why I have this error?
public static int DownStairs(int n) { int[] steps = new int[n + 1]; steps[n] = 1; steps[n - 1] = 1; for (int i = n-2; i>=0; i--) { for(int a = 1; a<=4; a++) { steps[i] += steps[i - a]; } } return steps[n]; } static void Main(string[] args) { int n = 5; DownStairs(n); }
-
How to delete multiple blank lines in a WPF DataGrid imported from an Excel file
I have a WPF DataGrid which I fill with imported data from an Excel file (*. Xlsx) through a class, the problem is that multiple blank lines are added to the end of the DataGrid that I don't see how to delete. I attach my code.
<DataGrid Name="dgvMuros" Height="210" Margin="8" VerticalAlignment="Top" Padding="5,6" ColumnWidth="50" IsReadOnly="False" AlternatingRowBackground="Azure" GridLinesVisibility="All" HeadersVisibility="Column" Loaded="dgvMuros_Loaded" CellEditEnding="DataGrid_CellEditEnding" ItemsSource="{Binding Data}" HorizontalGridLinesBrush="LightGray" VerticalGridLinesBrush="LightGray" > </DataGrid>
With this method I import the data from the Excel file.
public void ImportarMuros() { ExcelData dataFronExcel = new ExcelData(); this.dgvMuros.DataContext = dataFronExcel; txtTotMuros.Text = dataFronExcel.numMuros.ToString(); cmdAgregarMuros.IsEnabled = false; cmdBorrarMuros.IsEnabled = false; cmdImportar.IsEnabled = false; } public class ExcelData { public int numMuros { get; set; } public DataView Data { get { Excel.Application excelApp = new Excel.Application(); Excel.Workbook workbook; Excel.Worksheet worksheet; Excel.Range range; workbook = excelApp.Workbooks.Open(Environment.CurrentDirectory + "\\MurosEjemplo.xlsx"); worksheet = (Excel.Worksheet)workbook.Sheets["DatMuros"]; int column = 0; int row = 0; range = worksheet.UsedRange; DataTable dt = new DataTable(); dt.Columns.Add("Muro"); dt.Columns.Add("Long"); dt.Columns.Add("Esp"); dt.Columns.Add("X(m)"); dt.Columns.Add("Y(m)"); dt.Columns.Add("Dir"); for (row = 2; row < range.Rows.Count; row++) { DataRow dr = dt.NewRow(); for (column = 1; column <= range.Columns.Count; column++) { dr[column - 1] = Convert.ToString((range.Cells[row, column] as Excel.Range).Value); } dt.Rows.Add(dr); dt.AcceptChanges(); numMuros = dt.Rows.Count; } workbook.Close(true, Missing.Value, Missing.Value); excelApp.Quit(); return dt.DefaultView; } } }
-
bash functions, local variables, and exit codes
In a bash function, I'm trying to capture the output of a command along with it's exit code. Generally, my form is
some_function() { local rv=$(some_other_function) local code=$? echo "$rv" return $code }
but I notice that whenever I use 'local', then $? is ALWAYS 0. Like it's capturing the result of the assignment, not the called function. If I don't use 'local', then it works as expected:
$ foo() { local rv=$(false); echo "code is $?"; } $ foo code is 0 $ foo() { rv=$(false); echo "code is $?"; } $ foo code is 1
Can someone explain this to me? Obviously something fundamental here I just don't understand.
-
How do I set the src value of an iFrame to the text in an input field?
How would I be able to change the site in an iFrame to the value in an input field.
I want to do something like this:
iframe { height: 320px; width: calc(100vw - 24px); resize: both; overflow: auto; }
<input type="text"/> <button type="submit">🔎</button><br> <iframe src="https://xijxaj.glitch.me/new/index.html">
-
I keep getting a "variable declaration not allowed here" error
I keep getting a "variable declaration not allowed here" error. I am trying to input a menu selection to run queries that I have embedded in methods for a JDBC program.
import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; import java.sql.SQLException; import java.sql.*; import java.util.Scanner; /** * */ public class pbr { public static void main(String[] args) { if (args.length != 5) { System.out.println("USAGE: ser322.pbr <url> <user> <passwd> <driver> <menu>"); System.exit(0); } if (args[4].equals("menu")) Scanner scanner = new Scanner(System.in); System.out.println(("\n Choose from the following menu") + ("\nquery 1")+ ("\nquery 2")); String menuSelection = scanner.next(); if (menuSelection.equals("query1")) query1(args); if (menuSelection.equals("query2")) query2(args); else System.out.println("menu is the only accepted parameter");